0
\$\begingroup\$

I am trying to create a circular stage like so:

Circular board with multicolored powers of 2

But I can only make a square:

Square board with red ones and white twos

\$\endgroup\$
  • 1
    \$\begingroup\$ 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? \$\endgroup\$ – user3797758 Nov 19 '17 at 22:30
1
\$\begingroup\$

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
}
\$\endgroup\$
  • \$\begingroup\$ @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. \$\endgroup\$ – Will Nov 20 '17 at 4:00
  • \$\begingroup\$ @Will The OP's image shows 12 circles at r=2, not r=3. The single circle in the center is r=0. \$\endgroup\$ – bcrist Jun 5 '18 at 5:45
  • \$\begingroup\$ @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 \$\endgroup\$ – Bálint Jun 5 '18 at 6:07

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.