~ubuntu-branches/ubuntu/vivid/hamster-applet/vivid

« back to all changes in this revision

Viewing changes to hamster/pytweener.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio, Robert Ancell, Andrew Starr-Bochicchio
  • Date: 2009-12-22 17:52:52 UTC
  • mfrom: (1.1.13 upstream) (5.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091222175252-2r447ri9x56hi4kl
Tags: 2.29.4-0ubuntu1
[ Robert Ancell ]
* debian/control.in:
  - Remove old debian VCS links

[ Andrew Starr-Bochicchio ]
* New upstream release. (LP: #488783)
 - Fixed problems with hamster interfering with 
   screensaver hibernation code. (LP: #448438)
 - Fixes to the dropdown in compiz (not spanning
   over virtual desktops anymore). (LP: #303572)

* Merge with Debian testing, remaining Ubuntu changes:
 - Adapt debian/watch to take unstable version.
 - Point Vcs field at lp:~ubuntu-desktop/hamster-applet/ubuntu

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# pyTweener
 
2
#
 
3
# Tweening functions for python
 
4
#
 
5
# Heavily based on caurina Tweener: http://code.google.com/p/tweener/
 
6
#
 
7
# Released under M.I.T License - see above url
 
8
# Python version by Ben Harling 2009 
 
9
import math
 
10
 
 
11
class Tweener:
 
12
    def __init__(self, duration = 0.5, tween = None):
 
13
        """Tweener
 
14
        This class manages all active tweens, and provides a factory for
 
15
        creating and spawning tween motions."""
 
16
        self.currentTweens = []
 
17
        self.defaultTweenType = tween or Easing.Cubic.easeInOut
 
18
        self.defaultDuration = duration or 1.0
 
19
 
 
20
    def hasTweens(self):
 
21
        return len(self.currentTweens) > 0
 
22
 
 
23
 
 
24
    def addTween(self, obj, **kwargs):
 
25
        """ addTween( object, **kwargs) -> tweenObject or False
 
26
 
 
27
            Example:
 
28
            tweener.addTween( myRocket, throttle=50, setThrust=400, tweenTime=5.0, tweenType=tweener.OUT_QUAD )
 
29
 
 
30
            You must first specify an object, and at least one property or function with a corresponding
 
31
            change value. The tween will throw an error if you specify an attribute the object does
 
32
            not possess. Also the data types of the change and the initial value of the tweened item
 
33
            must match. If you specify a 'set' -type function, the tweener will attempt to get the
 
34
            starting value by call the corresponding 'get' function on the object. If you specify a 
 
35
            property, the tweener will read the current state as the starting value. You add both 
 
36
            functions and property changes to the same tween.
 
37
 
 
38
            in addition to any properties you specify on the object, these keywords do additional
 
39
            setup of the tween.
 
40
 
 
41
            tweenTime = the duration of the motion
 
42
            tweenType = one of the predefined tweening equations or your own function
 
43
            onCompleteFunction = specify a function to call on completion of the tween
 
44
            onUpdateFunction = specify a function to call every time the tween updates
 
45
            tweenDelay = specify a delay before starting.
 
46
            """
 
47
        if "tweenTime" in kwargs:
 
48
            t_time = kwargs.pop("tweenTime")
 
49
        else: t_time = self.defaultDuration
 
50
 
 
51
        if "tweenType" in kwargs:
 
52
            t_type = kwargs.pop("tweenType")
 
53
        else: t_type = self.defaultTweenType
 
54
 
 
55
        if "onCompleteFunction" in kwargs:
 
56
            t_completeFunc = kwargs.pop("onCompleteFunction")
 
57
        else: t_completeFunc = None
 
58
 
 
59
        if "onUpdateFunction" in kwargs:
 
60
            t_updateFunc = kwargs.pop("onUpdateFunction")
 
61
        else: t_updateFunc = None
 
62
 
 
63
        if "tweenDelay" in kwargs:
 
64
            t_delay = kwargs.pop("tweenDelay")
 
65
        else: t_delay = 0
 
66
 
 
67
        tw = Tween( obj, t_time, t_type, t_completeFunc, t_updateFunc, t_delay, **kwargs )
 
68
        if tw:    
 
69
            self.currentTweens.append( tw )
 
70
        return tw
 
71
 
 
72
    def removeTween(self, tweenObj):
 
73
        if tweenObj in self.currentTweens:
 
74
            tweenObj.complete = True
 
75
            #self.currentTweens.remove( tweenObj )
 
76
 
 
77
    def getTweensAffectingObject(self, obj):
 
78
        """Get a list of all tweens acting on the specified object
 
79
        Useful for manipulating tweens on the fly"""
 
80
        tweens = []
 
81
        for t in self.currentTweens:
 
82
            if t.target is obj:
 
83
                tweens.append(t)
 
84
        return tweens
 
85
 
 
86
    def removeTweeningFrom(self, obj):
 
87
        """Stop tweening an object, without completing the motion
 
88
        or firing the completeFunction"""
 
89
        for t in self.currentTweens:
 
90
            if t.target is obj:
 
91
                t.complete = True
 
92
 
 
93
    def finish(self):
 
94
        #go to last frame for all tweens
 
95
        for t in self.currentTweens:
 
96
            t.update(t.duration)
 
97
        self.currentTweens = []
 
98
 
 
99
    def update(self, timeSinceLastFrame):
 
100
        removable = []
 
101
        for t in self.currentTweens:
 
102
            t.update(timeSinceLastFrame)
 
103
 
 
104
            if t.complete:
 
105
                removable.append(t)
 
106
                
 
107
        for t in removable:
 
108
            self.currentTweens.remove(t)
 
109
            
 
110
 
 
111
class Tween(object):
 
112
    def __init__(self, obj, tduration, tweenType, completeFunction, updateFunction, delay, **kwargs):
 
113
        """Tween object:
 
114
            Can be created directly, but much more easily using Tweener.addTween( ... )
 
115
            """
 
116
        #print obj, tduration, kwargs
 
117
        self.duration = tduration
 
118
        self.delay = delay
 
119
        self.target = obj
 
120
        self.tween = tweenType
 
121
        self.tweenables = kwargs
 
122
        self.delta = 0
 
123
        self.completeFunction = completeFunction
 
124
        self.updateFunction = updateFunction
 
125
        self.complete = False
 
126
        self.tProps = []
 
127
        self.tFuncs = []
 
128
        self.paused = self.delay > 0
 
129
        self.decodeArguments()
 
130
 
 
131
    def decodeArguments(self):
 
132
        """Internal setup procedure to create tweenables and work out
 
133
           how to deal with each"""
 
134
 
 
135
        if len(self.tweenables) == 0:
 
136
            # nothing to do 
 
137
            print "TWEEN ERROR: No Tweenable properties or functions defined"
 
138
            self.complete = True
 
139
            return
 
140
 
 
141
        for k, v in self.tweenables.items():
 
142
 
 
143
        # check that its compatible
 
144
            if not hasattr( self.target, k):
 
145
                print "TWEEN ERROR: " + str(self.target) + " has no function " + k
 
146
                self.complete = True
 
147
                break
 
148
 
 
149
            prop = func = False
 
150
            startVal = 0
 
151
            newVal = v
 
152
 
 
153
            try:
 
154
                startVal = self.target.__dict__[k]
 
155
                prop = k
 
156
                propName = k
 
157
 
 
158
            except:
 
159
                func = getattr( self.target, k)
 
160
                funcName = k
 
161
 
 
162
            if func:
 
163
                try:
 
164
                    getFunc = getattr(self.target, funcName.replace("set", "get") )
 
165
                    startVal = getFunc()
 
166
                except:
 
167
                    # no start value, assume its 0
 
168
                    # but make sure the start and change
 
169
                    # dataTypes match :)
 
170
                    startVal = newVal * 0
 
171
                tweenable = Tweenable( startVal, newVal - startVal)    
 
172
                newFunc = [ k, func, tweenable]
 
173
 
 
174
                #setattr(self, funcName, newFunc[2])
 
175
                self.tFuncs.append( newFunc )
 
176
 
 
177
 
 
178
            if prop:
 
179
                tweenable = Tweenable( startVal, newVal - startVal)    
 
180
                newProp = [ k, prop, tweenable]
 
181
                self.tProps.append( newProp )  
 
182
 
 
183
 
 
184
    def pause( self, numSeconds=-1 ):
 
185
        """Pause this tween
 
186
            do tween.pause( 2 ) to pause for a specific time
 
187
            or tween.pause() which pauses indefinitely."""
 
188
        self.paused = True
 
189
        self.delay = numSeconds
 
190
 
 
191
    def resume( self ):
 
192
        """Resume from pause"""
 
193
        if self.paused:
 
194
            self.paused=False
 
195
 
 
196
    def update(self, ptime):
 
197
        """Update this tween with the time since the last frame
 
198
            if there is an update function, it is always called
 
199
            whether the tween is running or paused"""
 
200
            
 
201
        if self.complete:
 
202
            return
 
203
        
 
204
        if self.paused:
 
205
            if self.delay > 0:
 
206
                self.delay = max( 0, self.delay - ptime )
 
207
                if self.delay == 0:
 
208
                    self.paused = False
 
209
                    self.delay = -1
 
210
                if self.updateFunction:
 
211
                    self.updateFunction()
 
212
            return
 
213
 
 
214
        self.delta = min(self.delta + ptime, self.duration)
 
215
 
 
216
 
 
217
        for propName, prop, tweenable in self.tProps:
 
218
            self.target.__dict__[prop] = self.tween( self.delta, tweenable.startValue, tweenable.change, self.duration )
 
219
        for funcName, func, tweenable in self.tFuncs:
 
220
            func( self.tween( self.delta, tweenable.startValue, tweenable.change, self.duration ) )
 
221
 
 
222
 
 
223
        if self.delta == self.duration:
 
224
            self.complete = True
 
225
            if self.completeFunction:
 
226
                self.completeFunction()
 
227
 
 
228
        if self.updateFunction:
 
229
            self.updateFunction()
 
230
 
 
231
 
 
232
 
 
233
    def getTweenable(self, name):
 
234
        """Return the tweenable values corresponding to the name of the original
 
235
        tweening function or property. 
 
236
 
 
237
        Allows the parameters of tweens to be changed at runtime. The parameters
 
238
        can even be tweened themselves!
 
239
 
 
240
        eg:
 
241
 
 
242
        # the rocket needs to escape!! - we're already moving, but must go faster!
 
243
        twn = tweener.getTweensAffectingObject( myRocket )[0]
 
244
        tweenable = twn.getTweenable( "thrusterPower" )
 
245
        tweener.addTween( tweenable, change=1000.0, tweenTime=0.4, tweenType=tweener.IN_QUAD )
 
246
 
 
247
        """
 
248
        ret = None
 
249
        for n, f, t in self.tFuncs:
 
250
            if n == name:
 
251
                ret = t
 
252
                return ret
 
253
        for n, p, t in self.tProps:
 
254
            if n == name:
 
255
                ret = t
 
256
                return ret
 
257
        return ret
 
258
 
 
259
    def Remove(self):
 
260
        """Disables and removes this tween
 
261
            without calling the complete function"""
 
262
        self.complete = True
 
263
 
 
264
 
 
265
class Tweenable:
 
266
    def __init__(self, start, change):
 
267
        """Tweenable:
 
268
            Holds values for anything that can be tweened
 
269
            these are normally only created by Tweens"""
 
270
        self.startValue = start
 
271
        self.change = change
 
272
 
 
273
 
 
274
"""Robert Penner's easing classes ported over from actionscript by Toms Baugis (at gmail com).
 
275
There certainly is room for improvement, but wanted to keep the readability to some extent.
 
276
 
 
277
================================================================================
 
278
 Easing Equations
 
279
 (c) 2003 Robert Penner, all rights reserved. 
 
280
 This work is subject to the terms in
 
281
 http://www.robertpenner.com/easing_terms_of_use.html.
 
282
================================================================================
 
283
 
 
284
TERMS OF USE - EASING EQUATIONS
 
285
 
 
286
Open source under the BSD License.
 
287
 
 
288
All rights reserved.
 
289
 
 
290
Redistribution and use in source and binary forms, with or without modification,
 
291
are permitted provided that the following conditions are met:
 
292
 
 
293
    * Redistributions of source code must retain the above copyright notice,
 
294
      this list of conditions and the following disclaimer.
 
295
    * Redistributions in binary form must reproduce the above copyright notice,
 
296
      this list of conditions and the following disclaimer in the documentation
 
297
      and/or other materials provided with the distribution.
 
298
    * Neither the name of the author nor the names of contributors may be used
 
299
      to endorse or promote products derived from this software without specific
 
300
      prior written permission.
 
301
 
 
302
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
303
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
304
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
305
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 
306
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
307
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
308
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 
309
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
310
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
311
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
312
"""
 
313
class Easing:
 
314
    class Back:
 
315
        @staticmethod
 
316
        def easeIn(t, b, c, d, s = 1.70158):
 
317
            t = t / d
 
318
            return c * t**2 * ((s+1) * t - s) + b
 
319
 
 
320
        @staticmethod
 
321
        def easeOut (t, b, c, d, s = 1.70158):
 
322
            t = t / d - 1
 
323
            return c * (t**2 * ((s + 1) * t + s) + 1) + b
 
324
 
 
325
        @staticmethod
 
326
        def easeInOut (t, b, c, d, s = 1.70158):
 
327
            t = t / (d * 0.5)
 
328
            s = s * 1.525
 
329
            
 
330
            if t < 1:
 
331
                return c * 0.5 * (t**2 * ((s + 1) * t - s)) + b
 
332
 
 
333
            t = t - 2
 
334
            return c / 2 * (t**2 * ((s + 1) * t + s) + 2) + b
 
335
 
 
336
    class Bounce:
 
337
        @staticmethod
 
338
        def easeOut (t, b, c, d):
 
339
            t = t / d
 
340
            if t < 1 / 2.75:
 
341
                return c * (7.5625 * t**2) + b
 
342
            elif t < 2 / 2.75:
 
343
                t = t - 1.5 / 2.75
 
344
                return c * (7.5625 * t**2 + 0.75) + b
 
345
            elif t < 2.5 / 2.75:
 
346
                t = t - 2.25 / 2.75
 
347
                return c * (7.5625 * t**2 + .9375) + b
 
348
            else:
 
349
                t = t - 2.625 / 2.75
 
350
                return c * (7.5625 * t**2 + 0.984375) + b
 
351
 
 
352
        @staticmethod
 
353
        def easeIn (t, b, c, d):
 
354
            return c - Easing.Bounce.easeOut(d-t, 0, c, d) + b
 
355
 
 
356
        @staticmethod
 
357
        def easeInOut (t, b, c, d):
 
358
            if t < d * 0.5:
 
359
                return Easing.Bounce.easeIn (t * 2, 0, c, d) * .5 + b
 
360
 
 
361
            return Easing.Bounce.easeOut (t * 2 -d, 0, c, d) * .5 + c*.5 + b
 
362
 
 
363
 
 
364
        
 
365
    class Circ:
 
366
        @staticmethod
 
367
        def easeIn (t, b, c, d):
 
368
            t = t / d
 
369
            return -c * (math.sqrt(1 - t**2) - 1) + b
 
370
 
 
371
        @staticmethod
 
372
        def easeOut (t, b, c, d):
 
373
            t = t / d - 1
 
374
            return c * math.sqrt(1 - t**2) + b
 
375
 
 
376
        @staticmethod
 
377
        def easeInOut (t, b, c, d):
 
378
            t = t / (d * 0.5)
 
379
            if t < 1:
 
380
                return -c * 0.5 * (math.sqrt(1 - t**2) - 1) + b
 
381
            
 
382
            t = t - 2
 
383
            return c*0.5 * (math.sqrt(1 - t**2) + 1) + b
 
384
 
 
385
 
 
386
    class Cubic:
 
387
        @staticmethod
 
388
        def easeIn (t, b, c, d):
 
389
            t = t / d
 
390
            return c * t**3 + b
 
391
 
 
392
        @staticmethod
 
393
        def easeOut (t, b, c, d):
 
394
            t = t / d - 1
 
395
            return c * (t**3 + 1) + b
 
396
 
 
397
        @staticmethod
 
398
        def easeInOut (t, b, c, d):
 
399
            t = t / (d * 0.5)
 
400
            if t < 1:
 
401
                return c * 0.5 * t**3 + b
 
402
            
 
403
            t = t - 2
 
404
            return c * 0.5 * (t**3 + 2) + b
 
405
 
 
406
 
 
407
    class Elastic:
 
408
        @staticmethod
 
409
        def easeIn (t, b, c, d, a = 0, p = 0):
 
410
            if t==0: return b
 
411
 
 
412
            t = t / d            
 
413
            if t == 1: return b+c
 
414
            
 
415
            if not p: p = d * .3;
 
416
 
 
417
            if not a or a < abs(c):
 
418
                a = c
 
419
                s = p / 4
 
420
            else:
 
421
                s = p / (2 * math.pi) * math.asin(c / a)
 
422
            
 
423
            t = t - 1            
 
424
            return - (a * math.pow(2, 10 * t) * math.sin((t*d-s) * (2 * math.pi) / p)) + b
 
425
 
 
426
 
 
427
        @staticmethod
 
428
        def easeOut (t, b, c, d, a = 0, p = 0):
 
429
            if t == 0: return b
 
430
            
 
431
            t = t / d
 
432
            if (t == 1): return b + c
 
433
            
 
434
            if not p: p = d * .3;
 
435
 
 
436
            if not a or a < abs(c):
 
437
                a = c
 
438
                s = p / 4
 
439
            else:
 
440
                s = p / (2 * math.pi) * math.asin(c / a)
 
441
                
 
442
            return a * math.pow(2,-10 * t) * math.sin((t * d - s) * (2 * math.pi) / p) + c + b
 
443
 
 
444
 
 
445
        @staticmethod
 
446
        def easeInOut (t, b, c, d, a = 0, p = 0):
 
447
            if t == 0: return b
 
448
            
 
449
            t = t / (d * 0.5)
 
450
            if t == 2: return b + c
 
451
            
 
452
            if not p: p = d * (.3 * 1.5)
 
453
 
 
454
            if not a or a < abs(c):
 
455
                a = c
 
456
                s = p / 4
 
457
            else:
 
458
                s = p / (2 * math.pi) * math.asin(c / a)
 
459
                
 
460
            if (t < 1):
 
461
                t = t - 1
 
462
                return -.5 * (a * math.pow(2, 10 * t) * math.sin((t * d - s) * (2 * math.pi) / p)) + b
 
463
                
 
464
            t = t - 1
 
465
            return a * math.pow(2, -10 * t) * math.sin((t * d - s) * (2 * math.pi) / p) * .5 + c + b
 
466
 
 
467
 
 
468
    class Expo:
 
469
        @staticmethod
 
470
        def easeIn(t, b, c, d):
 
471
            if t == 0:
 
472
                return b
 
473
            else:
 
474
                return c * math.pow(2, 10 * (t / d - 1)) + b - c * 0.001
 
475
 
 
476
        @staticmethod
 
477
        def easeOut(t, b, c, d):
 
478
            if t == d:
 
479
                return b + c
 
480
            else:
 
481
                return c * (-math.pow(2, -10 * t / d) + 1) + b
 
482
 
 
483
        @staticmethod
 
484
        def easeInOut(t, b, c, d):
 
485
            if t==0:
 
486
                return b
 
487
            elif t==d:
 
488
                return b+c
 
489
 
 
490
            t = t / (d * 0.5)
 
491
            
 
492
            if t < 1:
 
493
                return c * 0.5 * math.pow(2, 10 * (t - 1)) + b
 
494
            
 
495
            return c * 0.5 * (-math.pow(2, -10 * (t - 1)) + 2) + b
 
496
 
 
497
 
 
498
    class Linear:
 
499
        @staticmethod
 
500
        def easeNone(t, b, c, d):
 
501
            return c * t / d + b
 
502
 
 
503
        @staticmethod
 
504
        def easeIn(t, b, c, d):
 
505
            return c * t / d + b
 
506
 
 
507
        @staticmethod
 
508
        def easeOut(t, b, c, d):
 
509
            return c * t / d + b
 
510
 
 
511
        @staticmethod
 
512
        def easeInOut(t, b, c, d):
 
513
            return c * t / d + b
 
514
 
 
515
 
 
516
    class Quad:
 
517
        @staticmethod
 
518
        def easeIn (t, b, c, d):
 
519
            t = t / d
 
520
            return c * t**2 + b
 
521
 
 
522
        @staticmethod
 
523
        def easeOut (t, b, c, d):
 
524
            t = t / d
 
525
            return -c * t * (t-2) + b
 
526
 
 
527
        @staticmethod
 
528
        def easeInOut (t, b, c, d):
 
529
            t = t / (d * 0.5)
 
530
            if t < 1:
 
531
                return c * 0.5 * t**2 + b
 
532
            
 
533
            t = t - 1
 
534
            return -c * 0.5 * (t * (t - 2) - 1) + b
 
535
 
 
536
 
 
537
    class Quart:
 
538
        @staticmethod
 
539
        def easeIn (t, b, c, d):
 
540
            t = t / d
 
541
            return c * t**4 + b
 
542
 
 
543
        @staticmethod
 
544
        def easeOut (t, b, c, d):
 
545
            t = t / d - 1
 
546
            return -c * (t**4 - 1) + b
 
547
 
 
548
        @staticmethod
 
549
        def easeInOut (t, b, c, d):
 
550
            t = t / (d * 0.5)
 
551
            if t < 1:
 
552
                return c * 0.5 * t**4 + b
 
553
            
 
554
            t = t - 2
 
555
            return -c * 0.5 * (t**4 - 2) + b
 
556
 
 
557
    
 
558
    class Quint:
 
559
        @staticmethod
 
560
        def easeIn (t, b, c, d):
 
561
            t = t / d
 
562
            return c * t**5 + b
 
563
 
 
564
        @staticmethod
 
565
        def easeOut (t, b, c, d):
 
566
            t = t / d - 1
 
567
            return c * (t**5 + 1) + b
 
568
 
 
569
        @staticmethod
 
570
        def easeInOut (t, b, c, d):
 
571
            t = t / (d * 0.5)
 
572
            if t < 1:
 
573
                return c * 0.5 * t**5 + b
 
574
            
 
575
            t = t - 2
 
576
            return c * 0.5 * (t**5 + 2) + b
 
577
 
 
578
    class Sine:
 
579
        @staticmethod
 
580
        def easeIn (t, b, c, d):
 
581
            return -c * math.cos(t / d * (math.pi / 2)) + c + b
 
582
 
 
583
        @staticmethod
 
584
        def easeOut (t, b, c, d):
 
585
            return c * math.sin(t / d * (math.pi / 2)) + b
 
586
 
 
587
        @staticmethod
 
588
        def easeInOut (t, b, c, d):
 
589
            return -c * 0.5 * (math.cos(math.pi * t / d) - 1) + b
 
590
 
 
591
 
 
592
    class Strong:
 
593
        @staticmethod
 
594
        def easeIn(t, b, c, d):
 
595
            return c * (t/d)**5 + b
 
596
 
 
597
        @staticmethod
 
598
        def easeOut(t, b, c, d):
 
599
            return c * ((t / d - 1)**5 + 1) + b
 
600
 
 
601
        @staticmethod
 
602
        def easeInOut(t, b, c, d):
 
603
            t = t / (d * 0.5)
 
604
            
 
605
            if t < 1:
 
606
                return c * 0.5 * t**5 + b
 
607
            
 
608
            t = t - 2
 
609
            return c * 0.5 * (t**5 + 2) + b
 
610
 
 
611
 
 
612
 
 
613
class TweenTestObject:
 
614
    def __init__(self):
 
615
        self.pos = 20
 
616
        self.rot = 50
 
617
 
 
618
    def update(self):
 
619
        print self.pos, self.rot
 
620
 
 
621
    def setRotation(self, rot):
 
622
        self.rot = rot
 
623
 
 
624
    def getRotation(self):
 
625
        return self.rot
 
626
 
 
627
    def complete(self):
 
628
        print "I'm done tweening now mommy!"
 
629
 
 
630
 
 
631
if __name__=="__main__":
 
632
    import time
 
633
    T = Tweener()
 
634
    tst = TweenTestObject()
 
635
    mt = T.addTween( tst, setRotation=500.0, tweenTime=2.5, tweenType=T.OUT_EXPO, 
 
636
                      pos=-200, tweenDelay=0.4, onCompleteFunction=tst.complete, 
 
637
                      onUpdateFunction=tst.update )
 
638
    s = time.clock()
 
639
    changed = False
 
640
    while T.hasTweens():
 
641
        tm = time.clock()
 
642
        d = tm - s
 
643
        s = tm
 
644
        T.update( d )
 
645
        if mt.delta > 1.0 and not changed:
 
646
 
 
647
            tweenable = mt.getTweenable( "setRotation" )
 
648
 
 
649
            T.addTween( tweenable, change=-1000, tweenTime=0.7 )
 
650
            T.addTween( mt, duration=-0.2, tweenTime=0.2 )
 
651
            changed = True
 
652
        #print mt.duration,
 
653
        print tst.getRotation(), tst.pos
 
654
        time.sleep(0.06)
 
655
    print tst.getRotation(), tst.pos