# LibGDX trying to create a matrix of circles

I am trying to create a circular stage like so:

But I can only make a square:

• Welcome to the Gamedev stack exchange :) Is it possible to post some source code of your existing solution so that we can see where you might be going wrong? Nov 19 '17 at 22:30

Each layer adds 2 * π circles (you can derive this from the circumference = 2 * r * π formula). What you should do is create an array of positions and put the position of the circles in it.

First loop between 0 (inclusively) and R (exclusively) where R is the amount of layers you want and let r be the current layer's index. Then each time create floor(2 * r * π) circles. You can get the positiom of the i-th circle in a specific layer, by using the

x = cos(2 * π / floor(2 * r * π) * i) * r
y = sin(2 * π / floor(2 * r * π) * i) * r


formula.

Together the whole code is

int getPoints(int R) {
points = []

for each r between 0 and R, do
x = cos(2 * π / floor(2 * r * π) * i) * r
y = sin(2 * π / floor(2 * r * π) * i) * r

for each i between 0 and floor(2 * r * π) do
points.push((x, y))
end
end

return points
}

• @OvidioRodriguez This creates a circle with 18 points for r=3, while the image shows only 12. If you want a "real" circle this is the way to go, but it you want that exact board, it would be better to hard-code it. (Or to more clearly define how you want to generate your board.
– Will
Nov 20 '17 at 4:00
• @Will The OP's image shows 12 circles at r=2, not r=3. The single circle in the center is r=0. Jun 5 '18 at 5:45
• @bcrist I don't really understand what you're trying to say with that. My version also generates 1 circle at r=0, 6 at r=1 and 12 at r=2 Jun 5 '18 at 6:07