Mercurial > MadButterfly
annotate pyink/tween.py @ 1150:6586cd10c92f
Refactory frameline.py
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sun, 26 Dec 2010 19:17:12 +0800 |
parents | e14ec6d1a661 |
children | 71c72e8d6755 |
rev | line source |
---|---|
1140 | 1 # -*- indent-tabs-mode: t; tab-width: 8; python-indent: 4; -*- |
2 # vim: sw=4:ts=8:sts=4 | |
3 import traceback | |
4 import math | |
5 class TweenObject: | |
6 def __init__(self,doc,dom): | |
7 self.document = doc | |
8 self.dom = dom | |
1141 | 9 try: |
10 self.width = float(dom.getAttribute("width")) | |
11 self.height = float(dom.getAttribute("height")) | |
12 except: | |
13 self.width = 640 | |
14 self.height = 480 | |
1140 | 15 |
16 def updateMapping(self): | |
17 self.nodeToItem={} | |
18 root = self.dom | |
19 self.updateMappingNode(root) | |
20 def updateMappingNode(self,node): | |
21 for c in node.childList(): | |
22 self.updateMappingNode(c) | |
1141 | 23 try: |
24 self.nodeToItem[c.getAttribute("id")] = c | |
25 except: | |
26 pass | |
1140 | 27 def updateTweenContent(self,obj, typ, source,dest,cur): |
28 """ | |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
29 Update the content of the duplicate scene group. We will |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
30 use the (start,end) and cur to calculate the percentage of |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
31 the tween motion effect and then use it to update the |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
32 transform matrix of the duplicated scene group. |
1140 | 33 """ |
34 | |
35 start = source.idx | |
36 end = dest.idx | |
37 print cur,start,end | |
38 percent = (cur-start)*1.0/(end-start) | |
39 i = 0 | |
40 s = source.ref.firstChild() | |
41 d = dest.ref.firstChild() | |
42 sources={} | |
43 dests={} | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
44 # Collect ref from the obj |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
45 o = obj.firstChild() |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
46 maps={} |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
47 while o: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
48 print "--->",o |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
49 try: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
50 ref = o.getAttribute("ref") |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
51 except: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
52 print o |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
53 ref = None |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
54 |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
55 if ref: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
56 maps[ref] = o |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
57 o = o.next() |
1140 | 58 # Collect all objects |
59 while d: | |
60 try: | |
1141 | 61 label = d.getAttribute("inkscape:label") |
1140 | 62 except: |
1141 | 63 d = d.next() |
1140 | 64 continue |
65 dests[label] = d | |
1141 | 66 d = d.next() |
1140 | 67 # Check if the object in the source exists in the destination |
68 s = source.ref.firstChild() | |
69 d = dest.ref.firstChild() | |
70 while s: | |
71 print s,d | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
72 sid = s.getAttribute("id") |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
73 if maps.has_key(sid): |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
74 o = maps[sid] |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
75 else: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
76 o = None |
1140 | 77 try: |
1141 | 78 label = s.getAttribute("inkscape:label") |
1140 | 79 # Use i8nkscape:label to identidy the equipvalent objects |
80 if label: | |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
81 if dests.has_key(label): |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
82 self.updateTweenObject(obj, typ, s, |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
83 dests[label], percent, o) |
1141 | 84 s = s.next() |
1140 | 85 continue |
86 except: | |
87 pass | |
88 # Search obejcts in the destination | |
89 while d: | |
90 try: | |
1141 | 91 d.getAttribute("inkscape:label") |
92 d = d.next() | |
1140 | 93 continue |
94 except: | |
95 pass | |
96 if s.name() == d.name(): | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
97 self.updateTweenObject(obj,typ,s,d,percent,o) |
1141 | 98 d = d.next() |
1140 | 99 break |
1141 | 100 d = d.next() |
101 s = s.next() | |
1140 | 102 |
103 def parseTransform(self,obj): | |
104 """ | |
105 Return the transform matrix of an object | |
106 """ | |
107 try: | |
1141 | 108 t = obj.getAttribute("transform") |
1140 | 109 print t |
110 if t[0:9] == 'translate': | |
111 print "translate" | |
112 fields = t[10:].split(',') | |
113 x = float(fields[0]) | |
114 fields = fields[1].split(')') | |
115 y = float(fields[0]) | |
116 return [1,0,0,1,x,y] | |
117 elif t[0:6] == 'matrix': | |
118 print "matrix" | |
119 fields=t[7:].split(')') | |
120 fields = fields[0].split(',') | |
121 return [float(fields[0]),float(fields[1]),float(fields[2]),float(fields[3]),float(fields[4]),float(fields[5])] | |
122 except: | |
123 #traceback.print_exc() | |
124 return [1,0,0,1,0,0] | |
125 | |
126 def invA(self,m): | |
127 d = m[0]*m[3]-m[2]*m[1] | |
128 return [m[3]/d, -m[1]/d, -m[2]/d, m[0]/d, (m[1]*m[5]-m[4]*m[3])/d, (m[4]*m[2]-m[0]*m[5])/d] | |
129 | |
130 def mulA(self,a,b): | |
131 return [a[0]*b[0]+a[1]*b[2], | |
132 a[0]*b[1]+a[1]*b[3], | |
133 a[2]*b[0]+a[3]*b[2], | |
134 a[2]*b[1]+a[3]*b[3], | |
135 a[0]*b[4]+a[1]*b[5]+a[4], | |
136 a[2]*b[4]+a[3]*b[5]+a[5]] | |
137 | |
138 def decomposition(self,m): | |
139 """ | |
140 Decompose the affine matrix into production of translation,rotation,shear and scale. | |
141 The algorithm is documented at http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html | |
142 """ | |
143 if m[0]*m[3] == m[1]*m[2]: | |
144 print "The affine matrix is singular" | |
145 return [1,0,0,1,0,0] | |
146 A=m[0] | |
147 B=m[2] | |
148 C=m[1] | |
149 D=m[3] | |
150 E=m[4] | |
151 F=m[5] | |
152 sx = math.sqrt(A*A+B*B) | |
153 A = A/sx | |
154 B = B/sx | |
155 shear = m[0]*m[1]+m[2]*m[3] | |
156 C = C - A*shear | |
157 D = D - B*shear | |
158 sy = math.sqrt(C*C+D*D) | |
159 C = C/sy | |
160 D = D/sy | |
161 r = A*D-B*C | |
162 if r == -1: | |
163 shear = -shear | |
164 sy = -sy | |
165 R = math.atan2(B,A) | |
166 return [sx,sy, R, E,F] | |
167 | |
168 | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
169 def updateTweenObject(self,obj,typ,s,d,p,newobj): |
1140 | 170 """ |
171 Generate tweened object in the @obj by using s and d in the @p percent | |
172 http://lists.w3.org/Archives/Public/www-style/2010Jun/0602.html | |
173 """ | |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
174 if typ == 1: |
1140 | 175 if s.name() == 'svg:g': |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
176 if not newobj: |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
177 newobj = s.duplicate(self.document) |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
178 top = self.document.createElement("svg:g") |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
179 top.setAttribute("ref", s.getAttribute("id")) |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
180 top.appendChild(newobj) |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
181 obj.appendChild(top) |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
182 else: |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
183 top = newobj |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
184 pass |
1140 | 185 # Parse the translate or matrix |
186 sm = self.parseTransform(s) | |
187 dm = self.parseTransform(d) | |
188 top.setAttribute("transform","translate(%g,%g)" % ((dm[2]-sm[2])*p,(dm[5]-sm[5])*p)) | |
189 else: | |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
190 if not newobj: |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
191 top = s.duplicate(self.document) |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
192 top.setAttribute('ref', s.getAttribute('id')) |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
193 obj.appendChild(top) |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
194 else: |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
195 top = newobj |
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
196 pass |
1140 | 197 try: |
1141 | 198 sx = float(s.getAttribute("x")) |
199 sy = float(s.getAttribute("y")) | |
200 dx = float(d.getAttribute("x")) | |
201 dy = float(d.getAttribute("y")) | |
1140 | 202 tx = (dx-sx)*p |
203 ty = (dy-sy)*p | |
204 print tx,ty | |
205 top.setAttribute("transform","translate(%g,%g)" % (tx,ty)) | |
206 except: | |
207 traceback.print_exc() | |
208 pass | |
209 pass | |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
210 elif typ == 2: |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
211 self.updateTweenObjectScale(obj,s,d,p,newobj) |
1140 | 212 pass |
1150
6586cd10c92f
Refactory frameline.py
Thinker K.F. Li <thinker@codemud.net>
parents:
1146
diff
changeset
|
213 elif typ == 0: |
1140 | 214 newobj = s.duplicate(self.document) |
1141 | 215 newobj.setAttribute("ref", s.getAttribute("id")) |
1140 | 216 top = self.document.createElement("svg:g") |
217 top.appendChild(newobj) | |
218 obj.appendChild(top) | |
219 pass | |
220 | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
221 def updateTweenObjectScale(self,obj,s,d,p,newobj): |
1140 | 222 """ |
223 Generate a new group which contains the original group and then | |
224 add the transform matrix to generate a tween frame between the | |
225 origin and destination scene group. | |
226 | |
227 We will parse the transform matrix of the @s and @d and then | |
228 generate the matrix which is (1-p) of @s and p percent of @d. | |
229 """ | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
230 if newobj == None: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
231 newobj = s.duplicate(self.document) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
232 top = self.document.createElement("svg:g") |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
233 top.setAttribute("ref",s.getAttribute("id")) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
234 top.appendChild(newobj) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
235 obj.appendChild(top) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
236 else: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
237 top = newobj |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
238 newobj = top.firstChild() |
1140 | 239 |
240 if s.name() == 'svg:g': | |
241 # Parse the translate or matrix | |
242 # | |
243 # D = B inv(A) | |
244 try: | |
1141 | 245 item = self.nodeToItem[s.getAttribute("id")] |
1140 | 246 (ox,oy) = item.getCenter() |
247 except: | |
248 ox = 0 | |
249 oy = 0 | |
250 try: | |
1141 | 251 item = self.nodeToItem[d.getAttribute("id")] |
1140 | 252 (dx,dy) = item.getCenter() |
253 except: | |
254 dx = 0 | |
255 dy = 0 | |
256 | |
257 sm = self.parseTransform(s) | |
258 ss = self.decomposition(sm) | |
259 dm = self.parseTransform(d) | |
260 dd = self.decomposition(dm) | |
261 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] | |
262 sy = (ss[1]*(1-p)+dd[1]*p)/ss[0] | |
263 a = ss[2]*(1-p)+dd[2]*p-ss[2] | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
264 tx = ox*(1-p)+dx*p |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
265 ty = oy*(1-p)+dy*p |
1140 | 266 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] |
267 m = self.mulA([sx,0,0,sy,0,0],m) | |
268 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height]) | |
269 m = self.mulA([1,0,0,1,tx,self.height-ty],m) | |
270 | |
271 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) | |
272 else: | |
273 try: | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
274 try: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
275 sw = float(s.getAttribute("width")) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
276 except: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
277 sw = 1 |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
278 try: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
279 sh = float(s.getAttribute("height")) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
280 except: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
281 sh = 1 |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
282 try: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
283 dw = float(d.getAttribute("width")) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
284 except: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
285 dw = 1 |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
286 try: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
287 dh = float(d.getAttribute("height")) |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
288 except: |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
289 dh = 1 |
1140 | 290 try: |
1141 | 291 item = self.nodeToItem[s.getAttribute("id")] |
1140 | 292 (ox,oy) = item.getCenter() |
293 except: | |
294 ox = 0 | |
295 oy = 0 | |
296 try: | |
1141 | 297 item = self.nodeToItem[d.getAttribute("id")] |
1140 | 298 (dx,dy) = item.getCenter() |
299 except: | |
300 dx = 0 | |
301 dy = 0 | |
302 try: | |
303 sm = self.parseTransform(s) | |
304 ss = self.decomposition(sm) | |
305 except: | |
306 ss = [1,1,0,0,0] | |
307 pass | |
308 try: | |
309 dm = self.parseTransform(d) | |
310 dd = self.decomposition(dm) | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
311 print "dd=",dd |
1140 | 312 except: |
313 dd = [1,1,0,0,0] | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
314 dd[0] = dd[0]*dw/sw |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
315 dd[1] = dd[1]*dh/sh |
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
316 print "ss[0]=",ss[0],"dd[0]=",dd[0] |
1140 | 317 sx = (ss[0]*(1-p)+dd[0]*p)/ss[0] |
318 sy = (ss[1]*(1-p)+dd[1]*p)/ss[1] | |
1146
e14ec6d1a661
CHange the implementation to set the transformation matrix only. This is be more friendly for the animation inside the inskcape.
wycc
parents:
1141
diff
changeset
|
319 print "sx=",sx,"sy=",sy |
1140 | 320 a = ss[2]*(1-p)+dd[2]*p-ss[2] |
321 tx = ox*(1-p)+dx*p | |
322 ty = oy*(1-p)+dy*p | |
323 m = [math.cos(a),math.sin(a),-math.sin(a),math.cos(a),0,0] | |
324 m = self.mulA([sx,0,0,sy,0,0],m) | |
325 m = self.mulA(m,[1,0,0,1,-ox,oy-self.height]) | |
326 m = self.mulA([1,0,0,1,tx,self.height-ty],m) | |
327 | |
328 top.setAttribute("transform","matrix(%g,%g,%g,%g,%g,%g)" % (m[0],m[2],m[1],m[3],m[4],m[5])) | |
329 except: | |
330 traceback.print_exc() |