Drawing circles
Moderators: Shine, Insert_witty_name
Drawing circles
Does anyone have a function that can draw circles in Lua? [ka] gave me one, but it does not have the ability to choose a fill color. I need a fill color.
Thanks!
Thanks!
-
- Posts: 35
- Joined: Mon Aug 22, 2005 7:48 am
Code: Select all
function drawCirc( x, y, radius, color)
theta = 0
while theta<=360 do
screen:drawLine((math.sin( theta)*radius)+x, (math.cos(theta)*radius)+ y, (math.sin(theta+1)*radius )+x, (math.cos(theta+1)*radius )+y, color)
theta = theta+1
end
end
something like (pseudo code, I don't do lua yet)
Jim
Code: Select all
for q = -r to r
w=sqrt(r^2 - y^2)
line x-w,y+q to x+w,y+q
next
-
- Posts: 6
- Joined: Sat Dec 03, 2005 10:30 am
Heres one I just coded:
The syntax is simple:
Also, I made this one so it places not the center of the circle at the input x and y position, but the upper-left hand corner.
Thanks,
Josh.
EDIT: The outline of the circle, If you choose to outline it with a different color, is quite large. I am unsure on how to make it smaller, because of my poor geometry skills, but I'll fool around with it later @ home (at school right now lol).
Code: Select all
function drawCirc(x, y, radiusfill, color, fillcolor)
x=x+radiusfill
y=y+radiusfill
theta = 0
for radius = 1, radiusfill do
while theta<=360 do
if radius == radiusfill then fillcolor = color end
screen:drawLine((math.sin(theta)*radius)+x, (math.cos(theta)*radius)+ y, (math.sin(theta+1)*radius)+x, (math.cos(theta+1)*radius)+y, fillcolor)
theta = theta+1
end
theta = 0
end
end
Code: Select all
drawCirc (x position, y position, radius size, outline color, fill color)
Thanks,
Josh.
EDIT: The outline of the circle, If you choose to outline it with a different color, is quite large. I am unsure on how to make it smaller, because of my poor geometry skills, but I'll fool around with it later @ home (at school right now lol).
Jim wrote:something like (pseudo code, I don't do lua yet)JimCode: Select all
for q = -r to r w=sqrt(r^2 - y^2) line x-w,y+q to x+w,y+q next
In LUA, it uses commands more like C:
Code: Select all
for q = -r , r
w=sqrt(r^2 - y^2)
screen:drawLine(x-w,y+q,x+w,y+q)
end