Ellipse Test

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

Moderators: Shine, Insert_witty_name

Post Reply
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Ellipse Test

Post by KawaGeo »

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: Select all

-- 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
Image
Geo Massar
Retired Engineer
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

looks good
Chaosmachine Studios: High Quality Homebrew.
Post Reply