Drawing circles

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Teggles
Posts: 27
Joined: Mon Jan 16, 2006 9:30 am

Drawing circles

Post by Teggles »

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!
soulphalanx
Posts: 35
Joined: Mon Aug 22, 2005 7:48 am

Post by soulphalanx »

Code: Select all

function drawCirc( x, y, radius, color)

	theta = 0

	while theta<=360 do
		screen&#58;drawLine&#40;&#40;math.sin&#40;  theta&#41;*radius&#41;+x, &#40;math.cos&#40;theta&#41;*radius&#41;+  y, &#40;math.sin&#40;theta+1&#41;*radius  &#41;+x, &#40;math.cos&#40;theta+1&#41;*radius  &#41;+y, color&#41;
		theta = theta+1
	end
end
Teggles
Posts: 27
Joined: Mon Jan 16, 2006 9:30 am

Post by Teggles »

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.
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

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
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

something like (pseudo code, I don't do lua yet)

Code: Select all

for q = -r to r
w=sqrt&#40;r^2 - y^2&#41;
line x-w,y+q to x+w,y+q
next
Jim
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

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
joreofiorio35
Posts: 6
Joined: Sat Dec 03, 2005 10:30 am

Post by joreofiorio35 »

Heres one I just coded:

Code: Select all

function drawCirc&#40;x, y, radiusfill, color, fillcolor&#41; 
   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&#58;drawLine&#40;&#40;math.sin&#40;theta&#41;*radius&#41;+x, &#40;math.cos&#40;theta&#41;*radius&#41;+ y, &#40;math.sin&#40;theta+1&#41;*radius&#41;+x, &#40;math.cos&#40;theta+1&#41;*radius&#41;+y, fillcolor&#41; 
      		theta = theta+1 
   	end
   theta = 0 
   end
end 
The syntax is simple:

Code: Select all

drawCirc &#40;x position, y position, radius size, outline color, fill color&#41;
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).
Teggles
Posts: 27
Joined: Mon Jan 16, 2006 9:30 am

Post by Teggles »

Hey, I haven't tried it, but I'm assuming it'll work well. Thanks!
youresam
Posts: 87
Joined: Sun Nov 06, 2005 1:43 am

Post by youresam »

Jim wrote:something like (pseudo code, I don't do lua yet)

Code: Select all

for q = -r to r
w=sqrt&#40;r^2 - y^2&#41;
line x-w,y+q to x+w,y+q
next
Jim

In LUA, it uses commands more like C:

Code: Select all

for q = -r , r
w=sqrt&#40;r^2 - y^2&#41;
screen&#58;drawLine&#40;x-w,y+q,x+w,y+q&#41;
end
Post Reply