Implement basic animation
This commit is contained in:
@@ -7,13 +7,17 @@ class CircleLayout(LayoutManager):
|
||||
LayoutManager.__init__(self)
|
||||
|
||||
self._radium = radium
|
||||
self._angle = 0
|
||||
|
||||
def set_angle(self, angle):
|
||||
self._angle = angle
|
||||
|
||||
def layout_group(self, group):
|
||||
step = 2 * math.pi / len(group.get_actors())
|
||||
angle = 2 * math.pi
|
||||
angle = self._angle
|
||||
for actor in group.get_actors():
|
||||
self._update_position(actor, angle)
|
||||
angle -= step
|
||||
angle += step
|
||||
|
||||
def _update_position(self, actor, angle):
|
||||
x = math.cos(angle) * self._radium + self._radium
|
||||
|
||||
+13
-8
@@ -3,24 +3,29 @@ from sugar.scene.Actor import Actor
|
||||
class Group(Actor):
|
||||
def __init__(self):
|
||||
self._actors = []
|
||||
self._layout_manager = None
|
||||
self._layout = None
|
||||
|
||||
def add(self, actor):
|
||||
self._actors.append(actor)
|
||||
if self._layout_manager:
|
||||
self._layout_manager.layout_group(slef)
|
||||
self.do_layout()
|
||||
|
||||
def remove(self, actor):
|
||||
self._actors.remove(actor)
|
||||
if self._layout_manager:
|
||||
self._layout_manager.layout_group(self)
|
||||
self.do_layout()
|
||||
|
||||
def get_actors(self):
|
||||
return self._actors
|
||||
|
||||
def set_layout_manager(self, layout_manager):
|
||||
self._layout_manager = layout_manager
|
||||
self._layout_manager.layout_group(self)
|
||||
def set_layout(self, layout):
|
||||
self._layout = layout
|
||||
self.do_layout()
|
||||
|
||||
def get_layout(self):
|
||||
return self._layout
|
||||
|
||||
def do_layout(self):
|
||||
if self._layout:
|
||||
self._layout.layout_group(self)
|
||||
|
||||
def render(self, drawable):
|
||||
for actor in self._actors:
|
||||
|
||||
@@ -3,3 +3,7 @@ from sugar.scene.Group import Group
|
||||
class Stage(Group):
|
||||
def __init__(self):
|
||||
Group.__init__(self)
|
||||
self._fps = 50
|
||||
|
||||
def get_fps(self):
|
||||
return self._fps
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import gobject
|
||||
|
||||
class Timeline(gobject.GObject):
|
||||
__gsignals__ = {
|
||||
'next-frame': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([int])),
|
||||
'completed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([]))
|
||||
}
|
||||
|
||||
def __init__(self, stage, n_frames):
|
||||
gobject.GObject.__init__(self)
|
||||
|
||||
self._stage = stage
|
||||
self._fps = stage.get_fps()
|
||||
self._n_frames = n_frames
|
||||
self._current_frame = 0
|
||||
|
||||
def start(self):
|
||||
gobject.timeout_add(1000 / self._fps, self.__timeout_cb)
|
||||
|
||||
def get_n_frames(self):
|
||||
return self._n_frames
|
||||
|
||||
def __timeout_cb(self):
|
||||
self.emit('next-frame', self._current_frame)
|
||||
|
||||
# FIXME skip frames if necessary
|
||||
self._current_frame += 1
|
||||
|
||||
if self._current_frame < self._n_frames:
|
||||
return True
|
||||
else:
|
||||
self.emit('completed')
|
||||
return False
|
||||
Reference in New Issue
Block a user