| View previous topic :: View next topic |
| Author |
Message |
Teggles
Joined: 16 Jan 2006 Posts: 27
|
Posted: Mon Jan 16, 2006 9:35 am Post subject: 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! |
|
| Back to top |
|
 |
soulphalanx
Joined: 22 Aug 2005 Posts: 35
|
Posted: Mon Jan 16, 2006 10:42 am Post subject: |
|
|
| Code: |
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
|
|
|
| Back to top |
|
 |
Teggles
Joined: 16 Jan 2006 Posts: 27
|
Posted: Mon Jan 16, 2006 1:05 pm Post subject: |
|
|
| Not to be rude, but did you even read my post? I said that it needs to be able to fill the circle. That does not fill the circle. |
|
| Back to top |
|
 |
KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Mon Jan 16, 2006 1:53 pm Post subject: |
|
|
Originally, Lua Player does not have a fill command for circles like we do have one for rectangles.
Shine's team is working on implementation of PSPGL (similar to OpenGL) toward Lua Player. _________________ Geo Massar
Retired Engineer |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Mon Jan 16, 2006 4:04 pm Post subject: |
|
|
something like (pseudo code, I don't do lua yet)
| Code: |
for q = -r to r
w=sqrt(r^2 - y^2)
line x-w,y+q to x+w,y+q
next
|
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Mon Jan 16, 2006 11:19 pm Post subject: |
|
|
i was on coding non rectangular figures and filling support but dropped it;
cause i was not fast enough to follow the changes of every luaplayer release
greets
lumo _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
joreofiorio35
Joined: 03 Dec 2005 Posts: 6
|
Posted: Tue Jan 17, 2006 1:55 am Post subject: |
|
|
Heres one I just coded:
| Code: |
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
|
The syntax is simple:
| Code: |
drawCirc (x position, y position, radius size, outline color, fill color)
|
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). |
|
| Back to top |
|
 |
Teggles
Joined: 16 Jan 2006 Posts: 27
|
Posted: Tue Jan 17, 2006 11:35 am Post subject: |
|
|
| Hey, I haven't tried it, but I'm assuming it'll work well. Thanks! |
|
| Back to top |
|
 |
youresam
Joined: 06 Nov 2005 Posts: 87
|
Posted: Wed Jan 18, 2006 8:22 am Post subject: |
|
|
| Jim wrote: | something like (pseudo code, I don't do lua yet)
| Code: |
for q = -r to r
w=sqrt(r^2 - y^2)
line x-w,y+q to x+w,y+q
next
|
Jim |
In LUA, it uses commands more like C:
| Code: |
for q = -r , r
w=sqrt(r^2 - y^2)
screen:drawLine(x-w,y+q,x+w,y+q)
end
|
|
|
| Back to top |
|
 |
|