Quickreference: display elements in a circle

How to display elements in a circle? A small function to do that is:

public static function circle(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;
}
}

Parameters are:

  • items: the items to be displayed a a circle
  • center: the center of the circle
  • distance: the distance from the center
  • initialAngle: the angle of the first item. Zero means that the item wil be aligned orizontally with the center, on his right.

Here’s an example:

Graph examples

I’ve always been fascinated by networks, and everything that can be modeled as a graph. In some spare time one I’ve tried to model a simple graph structure in actionscript 3 that can be implemented to render some nice example. I want to extend it by adding some graph algorhythm like Breadth-first search, Depth-first seach, Dijkstra and others, just to keep mind busy in the summer, since in 3 days from now i’ll be officially unemployed.

So the first example consists in a bunch of nodes connected.. uhhu! Nodes can be activated, and each time this happens to a node, there is a chance that he activates his neighbours.

If you want to see the code, there are two steps: I’ve stored the code that models the network (the Graph class and the INode interface) in a simple framework of mine that you can checkout from here; then you can download the project as a zip file from this link)

As a references, you should see Levitated examples on networks, starting by this one or  by this one.