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
