Code: Select all
function Image:rotate(cw)
cw = cw or 1 -- clockwise by default
-- cw ~= 1 -> counter-clockwise
local w = self:width()
local h = self:height()
local result = Image.createEmpty(h, w)
for x = 0, w-1 do
for y = 0, h-1 do
if cw == 1 then
result:pixel(h-y-1, x, self:pixel(x,y))
else
result:pixel(y, w-x-1, self:pixel(x,y))
end
end
end
return result
end
Code: Select all
-- rotatetest.lua by Geo Massar, 2005 (aka KawaGeo)
dofile "LPut02.lua"
green = Color.new(0,255,0)
black = Color.new(0,0,0)
plate = Image.createEmpty(168,40)
plate:fillRect(0,0, 168,40, green)
plate:fillRect(2,2, 164,36, black)
plate:caption(10,6, "Hello", green, 4)
while true do
screen:clear()
left = (480 - plate:width()) / 2
top = (272 - plate:height()) / 2
screen:blit(left,top, plate)
screen:print(2,262, "Tested by Geo Massar", green)
screen.flip()
screen.waitVblankStart(60) -- pause for a second
plate = plate:rotate(-1)
end
Screenshot:
Now, guys and gals, how about submitting new useful functions for LPut? I'll check this thread periodically.
Thanks.