root/trunk/RBRapier/RBRapier/Tools/Animation/__init__.py

Revision 693, 3.1 kB (checked in by sholloway, 5 years ago)

*** empty log message ***

Line 
1 #!/usr/bin/env python
2 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 ##~ License
4 ##~
5 ##- The RuneBlade Foundation library is intended to ease some
6 ##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.)
7 ##- applications, while providing the flexibility to modularly change the
8 ##- architecture. Enjoy.
9 ##~
10 ##~ Copyright (C) 2002  TechGame Networks, LLC.
11 ##~
12 ##~ This library is free software; you can redistribute it and/or
13 ##~ modify it under the terms of the BSD style License as found in the
14 ##~ LICENSE file included with this distribution.
15 ##~
16 ##~ TechGame Networks, LLC can be reached at:
17 ##~ 3578 E. Hartsel Drive #211
18 ##~ Colorado Springs, Colorado, USA, 80920
19 ##~
20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21
22 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 #~ Imports
24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25
26 import time
27
28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 #~ Definitions
30 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31
32 class BlendBase(object):
33     pass
34
35 class TimeBlendBase(BlendBase):
36     def now(klass):
37         return time.clock()
38     now = classmethod(now)
39
40     def __call__(self):
41         return 0.
42
43 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
45 class TimeBlend(TimeBlendBase):
46     def __init__(self, start, end):
47         self.SetRange(start, end)
48
49     def __call__(self):
50         (s, e), n = self.timespan, self.now()
51         value = (n-s)/(e-s)
52         return max(min(value, 1.), 0.)
53
54     def SetSpan(self, span):
55         s = self.timespan[0]
56         self.timespan = s, s+span
57     def fromSpan(klass, span):
58         n = klass.now()
59         return klass(n, n+span)
60     fromSpan = classmethod(fromSpan)
61
62     def SetRange(self, start, end, relative=False):
63         if relative:
64             now = self.now()
65             start += now
66             end += now
67         self.timespan = start, end
68     def fromTimeRange(klass, start, end, relative=False):
69         if relative:
70             now = klass.now()
71             start += now
72             end += now
73         return klass(start, end)
74     fromTimeRange = classmethod(fromTimeRange)
75
76     def SetTimeSpan(self, start, end, relative=False):
77         if relative:
78             start += self.now()
79         self.timespan = start, start+span
80     def fromTimeSpan(klass, start, span, relative=False):
81         if relative:
82             start += klass.now()
83         return klass(start, start+span)
84     fromTimeSpan = classmethod(fromTimeSpan)
85
86 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87
88 class TimeOscillation(TimeBlendBase):
89     def __init__(self, period=1, start=None):
90         self.SetOscillation(period, start)
91
92     def __call__(self):
93         s, p, n = self.start, self.period, self.now()
94         value = abs(((n-s)%p)/(.5*p) - 1.)
95         return max(min(value, 1.), 0.)
96
97     def SetOscillation(self, period=1., start=None):
98         self.SetPeriod(period)
99         self.SetStart(start)
100
101     def SetStart(self, start=None):
102         if start is None:
103             self.start = self.now()
104         else: self.start = start
105
106     def SetPeriod(self, period=1.):
107         self.period = period
Note: See TracBrowser for help on using the browser.