-
Notifications
You must be signed in to change notification settings - Fork 0
/
Operations.py
157 lines (156 loc) · 5 KB
/
Operations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
from svgwrite import gradients
from utils import *
lingrad = gradients.LinearGradient
class Animate:
def __init__(self,obj):
self.object = obj
def zoom(self,times,frame=1):
obj = self.object
attribs = obj.current_state.attribs
size=10
if 'size' in dir(obj):
size=obj.size
elif 'size' in attribs:
size = attribs['size']
elif 'height' in attribs:
size = attribs['height']
inc = ((times*size)-size)/frame
for _ in range(frame):
size+=inc
obj.changeSize(size)
yield obj.current_state
def rotate(self,angle,frame=1):
obj = self.object
inc = angle/frame
cangle =0
for _ in range(frame):
cangle+=inc
obj.rotate(cangle)
yield obj.current_state
def flip(self,angle,frame=1):
obj = self.object
inc = angle/frame
cangle =0
for _ in range(frame):
cangle+=inc
obj.flip(cangle)
yield obj.current_state
def revolve(self,angle,center,frame=1):
obj = self.object
cangle = 0
inc = angle/frame
for _ in range(stepsize):
cangle+=inc
obj.revolve(cangle,center)
yield obj.current_state
def moveto(self,pos,frame=1):
obj = self.object
x1,y1 = obj.pos
x2,y2 = pos
i1 = (x2-x1)/frame
i2 = (y2-y1)/frame
for _ in range(frame):
x1,y1 = x1+i1,y1+i2
obj.changePosition((x1,y1))
yield obj.current_state
obj.changePosition(pos)
yield obj.current_state
def move(self,pos,frame=1):
obj = self.object
i1 = pos[0]/frame
i2 = pos[1]/frame
x,y = 0,0
for _ in range(frame):
x+=i1
y+=i2
obj.move(x,y)
yield obj.current_state
def changeAttribute(self,attribute,changes):
obj = self.object
for change in changes:
obj.changeAttribute(attribute,change)
yield obj.current_state
def fadein(self,frame=1):
obj = self.object
inc = .99/frame
o=0
for i in range(frame):
o+=inc
obj.changeStyle('opacity',o)
yield obj.current_state
def fadeout(self,frame=1):
obj = self.object
inc = .99/frame
o=1
for i in range(frame):
o-=inc
obj.changeStyle('opacity',o)
yield obj.current_state
def strokein(self,frame=1,top=0):
obj = self.object
screen = obj.screen
inc = 100/frame
o=0
attribs = obj.current_state.attribs
#Checking fill in style and object attributes(else 'white')
fill = attribs.pop("stroke") \
if "stroke" in attribs\
else \
(obj.popStyle("stroke")
if "stroke" in obj.style
else "white")
obj.changeAttribute('stroke','url(#creation3)')
if top:
x2,y2="0%","100%"
else:
x2,y2= "100%","0%"
lg = lingrad(id="creation3",x2=x2,y2=y2)
screen.add(lg)
for i in range(frame):
o+=inc
lg.elements=[]
lg.add_stop_color(offset=str(round(o,3))+"%",opacity=1,color=fill)\
.add_stop_color(offset=str(round(o,3))+"%",opacity=0,color=fill)
yield obj.current_state
attribs['stroke']=fill
screen.elements.remove(lg)
def create(self,frame=3,stroke=1):
p3=int(frame/3)
if stroke:
for f in self.strokein(int(p3)): yield f
else:
for f in self.fadein(int(p3)): yield f
frame = int(p3*2)
obj = self.object
screen = obj.screen
inc2 = 100/frame
inc1 = inc2*1.5
o1=0
o2=0
attribs = obj.current_state.attribs
#Checking fill in style and object attributes(else 'white')
fill = attribs.pop("fill") \
if "fill" in attribs\
else \
(obj.popStyle("fill")
if "fill" in obj.style
else "white")
obj.changeAttribute('fill','url(#creation3)')
lg = lingrad(id="creation3")
screen.add(lg)
for i in range(frame):
if o1<100:
o1+=inc1
o2+=inc2
else:
o2+=inc2
lg.elements=[]
lg.add_stop_color(offset=str(round(o2,3))+"%",opacity=1,color=fill)\
.add_stop_color(offset=str(round(o1,3))+"%",opacity=0,color=fill)
yield obj.current_state
attribs['fill']=fill
screen.elements.remove(lg)
def wait(self,frame):
obj= self.object
for _ in range(frame):
yield obj.current_state