pylint animator
This commit is contained in:
parent
4ad5928a74
commit
03e515b463
@ -28,13 +28,14 @@ class Animator(gobject.GObject):
|
|||||||
gobject.TYPE_NONE, ([])),
|
gobject.TYPE_NONE, ([])),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, time, fps=20, easing=EASE_OUT_EXPO):
|
def __init__(self, duration, fps=20, easing=EASE_OUT_EXPO):
|
||||||
gobject.GObject.__init__(self)
|
gobject.GObject.__init__(self)
|
||||||
self._animations = []
|
self._animations = []
|
||||||
self._time = time
|
self._duration = duration
|
||||||
self._interval = 1.0 / fps
|
self._interval = 1.0 / fps
|
||||||
self._easing = easing
|
self._easing = easing
|
||||||
self._timeout_sid = 0
|
self._timeout_sid = 0
|
||||||
|
self._start_time = None
|
||||||
|
|
||||||
def add(self, animation):
|
def add(self, animation):
|
||||||
self._animations.append(animation)
|
self._animations.append(animation)
|
||||||
@ -58,13 +59,13 @@ class Animator(gobject.GObject):
|
|||||||
self.emit('completed')
|
self.emit('completed')
|
||||||
|
|
||||||
def _next_frame_cb(self):
|
def _next_frame_cb(self):
|
||||||
current_time = min(self._time, time.time() - self._start_time)
|
current_time = min(self._duration, time.time() - self._start_time)
|
||||||
current_time = max(current_time, 0.0)
|
current_time = max(current_time, 0.0)
|
||||||
|
|
||||||
for animation in self._animations:
|
for animation in self._animations:
|
||||||
animation.do_frame(current_time, self._time, self._easing)
|
animation.do_frame(current_time, self._duration, self._easing)
|
||||||
|
|
||||||
if current_time == self._time:
|
if current_time == self._duration:
|
||||||
self.stop()
|
self.stop()
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
@ -75,18 +76,18 @@ class Animation(object):
|
|||||||
self.start = start
|
self.start = start
|
||||||
self.end = end
|
self.end = end
|
||||||
|
|
||||||
def do_frame(self, time, duration, easing):
|
def do_frame(self, t, duration, easing):
|
||||||
start = self.start
|
start = self.start
|
||||||
change = self.end - self.start
|
change = self.end - self.start
|
||||||
|
|
||||||
if time == duration:
|
if t == duration:
|
||||||
# last frame
|
# last frame
|
||||||
frame = self.end
|
frame = self.end
|
||||||
else:
|
else:
|
||||||
if easing == EASE_OUT_EXPO:
|
if easing == EASE_OUT_EXPO:
|
||||||
frame = change * (-pow(2, -10 * time/duration) + 1) + start;
|
frame = change * (-pow(2, -10 * t / duration) + 1) + start
|
||||||
elif easing == EASE_IN_EXPO:
|
elif easing == EASE_IN_EXPO:
|
||||||
frame = change * pow(2, 10 * (time / duration - 1)) + start;
|
frame = change * pow(2, 10 * (t / duration - 1)) + start
|
||||||
|
|
||||||
self.next_frame(frame)
|
self.next_frame(frame)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user