-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtween.py
40 lines (33 loc) · 926 Bytes
/
tween.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import vector
class LinearTween(object):
def __init__(self, a, b, speed):
self.a = a
self.b = b
self.t = 0.0
self.speed = speed
def step(self, dt):
if self.t < 1.0:
self.t += (dt * self.speed)
if self.t > 1.0:
self.t = 1.0
return self.a.lerp(self.b, self.t) if type(self.a) == vector.Vector3 else self.a.slerp(self.b, self.t)
else:
return self.b
def done(self):
return self.t == 1.0
def finish(self):
self.t = 1.0
return self.b
def snap(self, c):
self.a = self.b = c
self.t = 1.0
class PeriodicTimer(object):
def __init__(self, period):
self.count = 0
self.period = period
def tick(self):
self.count += 1
if self.count >= self.period:
self.count = 0
return True
return False