Drawing a pixel-y circle

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
stout
Citizen
Posts: 64
Joined: Sun Oct 07, 2012 4:42 pm

Drawing a pixel-y circle

Post by stout »

So I'm stuck on this.

Let's say you want to make some circles on a tilemap. Specifically, circles shaped like these.

I've successfully got squares and triangles going, using for loops that count though -ycount,ycount and -xcount,xcount, so if ycount is 4 and xcount is 2 you'd get a shape going -4,-2, -4,-1, -4, 0, -4, 1, -4, 2, and so on. And I've figured out some of the rules for these circles: if you start your radius as 3 and a variable - let's call it radcount - at 2, your radius goes up by 2 (to keep the number odd), your radcount goes up by 1, radius - radcount = your y and x counts (so a radius of 7 would give you a ycount 6, so you'd draw -6, -5, etc down to 0, then back up the positive side).

Code: Select all

3 / radcount 2
ycount = 1
xcount = 1

5 / radcount 3
ycount = 2
xcount = (2) 2, 1

7 / radcount 4
ycount = 3
xcount = (3) 3, 2, 1

9 / radcount 5
ycount = 4
xcount = (4) 4, 4, 3, 2

11 / radcount 6
ycount = 5
xcount = (5) 5, 5, 4, 3, 2

13 / radcount 7
ycount = 6
xcount = (6) 6, 6, 5, 5, 4, 2

15 / radcount 8
ycount = 7
xcount = (7) 7, 6, 6, 5, 4, 3, 1
counts are the number of tiles from the origin number. count * 2 + 1 = radius. The (number) is the "0" column, representing plain x. Then it's x+1, x+2, etc to the end of the row.
I can't figure out the rule for the length of each row (xcount), nor how to write this loop. Googling tells me that this is probably relevant to my interests but I can't figure out how to apply that, either.

Any help is appreciated.
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Drawing a pixel-y circle

Post by Kadoba »

Yeah you want the midpoint circle algorithm. Here's an example love for you.
MidpointCircleExample.love
(579 Bytes) Downloaded 206 times
stout
Citizen
Posts: 64
Joined: Sun Oct 07, 2012 4:42 pm

Re: Drawing a pixel-y circle

Post by stout »

Thanks! I'll spend some time parsing it.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 20 guests