@@ -154,7 +154,7 @@ def add(self, motion: Motion):
154154 self ._motions .add (iter (motion ))
155155
156156 def add_motion (self , id : int , end : Coord , ** kwargs ):
157- motion = Motion (self .canvas , id , ( end ,) , ** kwargs )
157+ motion = Motion (self .canvas , id , end , ** kwargs )
158158 self .add (motion )
159159
160160 def clear (self ):
@@ -172,31 +172,32 @@ class Motion:
172172 """
173173 canvas : tk .Canvas
174174 id : int
175- endpoints : Tuple [ Coord ]
175+ end : Coord
176176
177177 speed : int = 1
178178
179179 def start (self ) -> Generator [Callable ]:
180180 """
181181 The entry point for generating move commands.
182182 """
183- move = partial (self .canvas .move , self .id )
184-
185183 def frame (increment : Coord , count : int = 1 ):
186184 for _ in range (count ):
187185 move (* increment )
188186 self .canvas .master .update_idletasks ()
189187
190- for end in self .endpoints :
191- start = self .current
192- steps = round (start .distance (end ) / self .speed )
193- frames = round (steps / self .speed )
194- increment = (end - start ) / steps
188+ start = self .current
189+ steps = round (start .distance (self .end ) / self .speed )
190+ frames = round (steps / self .speed )
191+ increment = (self .end - start ) / steps
192+
193+ for _ in range (frames ):
194+ yield partial (frame , increment , round (steps / frames ))
195+ buffer = self .end - self .current
196+ yield partial (frame , buffer )
195197
196- for _ in range (frames ):
197- yield partial (frame , increment , round (steps / frames ))
198- buffer = end - self .current
199- yield partial (frame , buffer )
198+ @property
199+ def move (self ):
200+ return partial (self .canvas .move , self .id )
200201
201202 @property
202203 def current (self ):
@@ -213,3 +214,7 @@ def __hash__(self):
213214
214215 def __eq__ (self ):
215216 return isinstance (self , type (other )) and self .__key () == other .__key ()
217+
218+
219+ class BounceBall (Motion ):
220+
0 commit comments