forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Ellipse Test

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
KawaGeo



Joined: 27 Aug 2005
Posts: 191
Location: Calif Mountains

PostPosted: Mon Sep 05, 2005 3:43 am    Post subject: Ellipse Test Reply with quote

I have coded drawEllipse function in Lua. The arguments are the same as fillRect, in addition of an extra argument, number of segments around the ellipse. The code and screenshot are given here.

NOTE: Don't use screen as an object to draw ellipses upon directly. I don't know why. Maybe Shine could explain.

Code:

-- ellipseTest.lua by Geo Massar, 2005  (aka Geo Massar)

PI2 = math.pi * 2

function math.round(num, dp)
  local mult = 10^(dp or 0)
  return math.floor(num  * mult + 0.5) / mult
end

function Image:drawEllipse(x1,y1, x2,y2, segments, color)
  local a = (x2-x1) / 2; local x0 = (x2+x1) / 2
  local b = (y2-y1) / 2; local y0 = (y2+y1) / 2
  x1, y1 = x0, y0 + b
  for i = 1, segments do
    x2 = math.round(x0 + a * math.sin(PI2*i/segments))
    y2 = math.round(y0 + b * math.cos(PI2*i/segments))
    self:drawLine(x1,y1, x2,y2, color)
    x1,y1 = x2,y2
  end
end

green = Color.new(0, 255, 0)

panel = Image.createEmpty(400,200)
for i = 0, 4 do
  panel:drawEllipse(50*i,0, 400-50*i,200, 60, green)
end

screen:blit(40,36, panel)
screen:print(2,262, "Ellipse Test by Geo Massar, 2005 (aka KawaGeo)", green)
screen.flip()

while true do
  screen.waitVblankStart()
end


_________________
Geo Massar
Retired Engineer
Back to top
View user's profile Send private message Send e-mail
chaos



Joined: 10 Apr 2005
Posts: 135

PostPosted: Mon Sep 05, 2005 12:21 pm    Post subject: Reply with quote

looks good
_________________
Chaosmachine Studios: High Quality Homebrew.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group