as3 place items around the circle

var arr:Array = [a1,a2,a3,a4,a5,a6,a7];
calculateCircle(arr,new Point(150,150),100);

function calculateCircle(items:Array, center:Point, distance:Number = -1, initialAngle:Number = 0):void
{
	var step:Number = (2 * Math.PI) / items.length;
	var angle:Number = initialAngle;
	
	for each (var d:DisplayObject in items)
	{
		if (distance < 0)
		{
			distance = d.height + 10 / Math.sin(step);
		}
		
		d.x = center.x + distance * Math.cos(angle);
		d.y = center.y + distance * Math.sin(angle);
		angle += step;
	}
}

Advertisements