annotate pyink/tween.py @ 1140:d4dbcb93aee0

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