I'm trying some math things to learn pico8 and programming in general.

After a few days and realizing that the square root in lua (and in every language?) only gives positive numbers, I’ve come to this monster to draw a simple circle haha

function _init() end function _update60() cls(1) end function _draw() --coordinates line(64,0,64,128,2) line(0,64,128,64,2) manual_circle() circ(64,64,63) end function manual_circle() for x=0,50 do radius=50 local y=-sqrt((radius^2)-(x^2)) pset(x+64,y+64,11) end for x=-50,0 do radius=50 local y=-sqrt((radius^2)-(x^2)) pset(x+64,y+64,11) end for x=0,50 do radius=50 local y=-sqrt((radius^2)-(x^2)) pset(x+64,-y+64,11) end for x=-50,0 do radius=50 local y=-sqrt((radius^2)-(x^2)) pset(x+64,-y+64,11) end end |

And it looks like this:

as you can see the function doesn't print the pixels continuosly as the circ function, probably because of the square root giving decimals.

What is the correct way of drawing a circle “manually”???

Thank you!

Search Google for: Bresenham circle drawing algorithm

https://en.wikipedia.org/wiki/Midpoint_circle_algorithm may be good as well.

Check out this thread on the Minsky circle: https://www.lexaloffle.com/bbs/?tid=29976

(the title is no longer entirely correct, but it's still an interesting and surprisingly performant alternative to Bresenham)

[Please log in to post a comment]