arrange div elements in circle and square

1k Views Asked by At

I n number of divs which are arranged in a circle using javascript. Right now i set the dimension of each div to 40*40. Below is what i am able to achieve so far. This is how i find X & Y of each div.

x = 100 * Math.cos(angle) + hCenter;
y = 100 * Math.sin(angle) + vCenter;

where hCenter & vCenter are center point of the screen

enter image description here

  1. When there are many circles they start overlapping each other. How can i find the height & width of each div so that they fit in circle with a little space between each other.

  2. How can i arrange the same circles in the square. Means animate from circle to square. How to find new X,Y position of each div.