Log In  


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!

1


1

Search Google for: Bresenham circle drawing algorithm

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


1

wieczu: wow didn't think this was such a complicated thing! Thank you very much, that's exactly what I was looking for!

qouka: you are right! I just wanted to see the most “manual” way of doing it.


wieczu answer (and the many variants) is the only appropriate option to draw a circle on a computer screen.
Sin/cos are ok but getting the right number of slices to not have holes would be super complex!
(beside sin/cos are/were notoriously slow)


1

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)


Fascinating! The native pico8 circle function should have been something really hard to do! Thanks! :D



[Please log in to post a comment]