13
|
1 class Interpolator(object):
|
|
2 def __init__(self, values=()):
|
|
3 self.values = tuple(values)
|
|
4 self.start_values = tuple(values)
|
|
5 self.end_values = tuple(values)
|
|
6 self.start_frame = 0
|
|
7 self.end_frame = 0
|
|
8
|
|
9
|
|
10 def set_interpolation_start(self, frame, values):
|
|
11 self.start_values = tuple(values)
|
|
12 self.start_frame = frame
|
|
13
|
|
14
|
|
15 def set_interpolation_end(self, frame, values):
|
|
16 self.end_values = tuple(values)
|
|
17 self.end_frame = frame
|
|
18
|
|
19
|
|
20 def set_interpolation_end_frame(self, end_frame):
|
|
21 self.end_frame = end_frame
|
|
22
|
|
23
|
|
24 def set_interpolation_end_values(self, values):
|
|
25 self.end_values = tuple(values)
|
|
26
|
|
27
|
|
28 def update(self, frame):
|
|
29 if frame >= self.end_frame:
|
|
30 self.values = tuple(self.end_values)
|
|
31 self.start_values = tuple(self.end_values)
|
|
32 self.start_frame = frame
|
|
33 else:
|
|
34 truc = float(frame - self.start_frame) / float(self.end_frame - self.start_frame)
|
|
35 self.values = tuple(start_value + truc * (end_value - start_value)
|
|
36 for (start_value, end_value) in zip(self.start_values, self.end_values))
|