-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanimation.py
35 lines (26 loc) · 1021 Bytes
/
animation.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
#!/usr/bin/env python
# animation.py for storing image sequences and key
class Animation:
def __init__(self, key="", sequence=[], attrs={}):
self.key = key
self.sequence = sequence
self.attrs = attrs
def add_frame(self, frame):
self.sequence.append(frame)
def set_key(self, key):
self.key = key
def get_reversed(self):
frame = self.attrs.get("hold_frame", -1)
new_attrs = self.attrs.copy()
return Animation("rev_" + self.key, self.sequence[::-1], new_attrs)
def __getitem__(self, key):
return self.sequence[-1] if len(
self.sequence) <= key else self.sequence[key]
def __len__(self):
return len(self.sequence)
def is_latch(self):
return self.attrs.get("latch", True)
def get_latched(self):
frame = self.attrs.get("hold_frame", -1)
newAttrs = self.attrs.copy()
return Animation("hold_" + self.key, [self.sequence[frame]])