LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Circles and For Loops

Root / Programming Questions / [.]

randoCreated:
Hey, how can I make a circle using a for loop? That seems the best way I can get a completely filled circle, but I can't quite get the shape. Here is my code:
DEF GCIRCFL CENTX,CENTY,RADI
FOR X=CENTX-RADI TO CENTX+RADI
 FOR Y=CENTY-RADI TO CENTY+RADI
  GLINE CENTX,CENTY,X,Y
 NEXT
NEXT
END
GCIRCFL 200,120,20'I want this to make a circle
I know this makes a box, and how that works, but no matter how I change it I can't make it a circle. Can anyone help?


https://smilebasicsource.com/page?pid=1051 I used Simeon’s code and it works fine.

https://smilebasicsource.com/page?pid=1051 I used Simeon’s code and it works fine.
It doesn't work when the circle is completely in an offscreen part of the GRP.

https://smilebasicsource.com/page?pid=1303
But what if 2 circles overlap?

https://smilebasicsource.com/page?pid=1303
But what if 2 circles overlap?
it uses a special color for the bounding circle which isn't used anywhere else (int form: 8) then it fills that circle with the fill color using GPAINT, specifying the special color as the boundary color so it will completely ignore other colors until it hits the bounding circle then it redraws the bounding circle with the actual (usually fill) color so there isn't any special color (8) left to mess with future filled circle drawing

Yeah. And color 8 is RGB(0,0,0,8) All colors that are transparent (RGB(0,anything,anything,anything)) look identical, so there's no reason that anyone would use 8 rather than 0. It's safe to assume that these colors won't be used for anything else.

If you aren't looking for real time speed or perfect accuracy, I would approximate it with triangles layed out pie chart style (triangle fan). You could even change the triangle count based on radius, although less than 3 or more than 360 is probably silly. This way you don't have to worry about flood fill running into the stop color prematurely or if it goes offscreen. (I assume the flood fill would be faster just due to less function calls) You could also try just putting in a Sprite of a filled circle and shrinking/ growing it as needed.

What you could do is draw the filled circle using GCIRCLE/GPAINT on an unused empty graphics page, then GCOPY it to the main page, if you NEED to use weird transparent pixels for some reason.

...GCOPY it to the main page, if you NEED to use weird transparent pixels for some reason.
at that point you'd probably just want to use a scaled circle sprite