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 circleI 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=1303But 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 drawinghttps://smilebasicsource.com/page?pid=1303But what if 2 circles overlap?
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.