-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanimator.py
More file actions
28 lines (25 loc) · 792 Bytes
/
Copy pathanimator.py
File metadata and controls
28 lines (25 loc) · 792 Bytes
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
'''
'''
import time
class Animator(object):
"""docstring for Animator"""
def __init__(self, data):
super(Animator, self).__init__()
self.initial_data = self.final_data = self.data = data
self.end_time = self.start_time = time.time()
def animate(self, final_data, animation_time):
self.start_time = time.time()
self.end_time = time.time() + animation_time
self.initial_data = dict(self.data)
self.final_data = final_data
def update(self):
ct = time.time()
x = self.end_time - ct
if x <= 0.0:
for key in self.final_data:
self.data[key] = self.final_data[key]
else:
for key in self.final_data:
gradient = 1.0 * (self.final_data[key] - self.data[key]) / x
self.data[key] = gradient * (ct - self.start_time) + self.data[key]
self.start_time = ct