Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/scene/CircleLayout.py
blob: 545b9971fe9c81f7787349cfac12a493443b4b89 (plain)
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
import math

from sugar.scene.LayoutManager import LayoutManager

class CircleLayout(LayoutManager):
	def __init__(self, radius):
		LayoutManager.__init__(self)

		self._radius = radius
		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 = self._angle
		for actor in group.get_actors():
			self._update_position(actor, angle)
			angle += step

	def _update_position(self, actor, angle):
		x = math.cos(angle) * self._radius + self._radius
		y = math.sin(angle) * self._radius + self._radius
		actor.set_position(int(x + 0.5), int(y + 0.5))