views:

319

answers:

1

Where can i find some algorithm to position some objects in canvas in a clever way? I'm using javascript (with Raphael svg library), but examples with other languages (or pseudo-language) are welcome. Geometry isn't my strong point =)

For example have 600x800 canvas, and i want to place n objects sized 60x60 in smart ways, for example:
- an algorithm to position objects along m concentric circles with o offset.
- an algorithm to position objects along m concentric squares, but an alternate frequency (the result can be like a chessboard)

And similar examples.. i'm just looking some working examples to adapt to my case. Thank you in advance =)

+1  A: 

For Circle:

Inputs: CenterPt(presumably 300,400), RadiusLargestCircle(presumably 270 to ensure your objects are all on screen) RadiusDelta(60 ensures no overlapping objects assuming objects are circles)

calculate number of circles ( (RadiusLargestCircle -2*RadiusDelta) / RadiusDelta )

for each circle

  RadCir= RadiusLargestCircle - (CircleNum*RadiusDelta)

(I'll finish this properly later, gotta head now)

but essentially first object centerpt goes at x=radiusLargestCircle, y=0

divide object 2*radius into circumferance of circle

for num objects

useing parametric equation of circle, place object at x radians from previous one

next Circle

Overflow