KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Fri Sep 16, 2005 7:47 am Post subject: New additional function for LPut Utility Library |
|
|
The new additional function is Shine's rotate(). The editted code is shown:
| Code: | 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
|
And test program is shown:
| Code: | -- 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
|
The program is tested on Lua Player for Windows. It rotates the plate 90 degrees counter-clockwise. Try it for yourself. Remove the argument, -1, in the rotate function for clockwise spinning. Get new release of LPut02.lua at my webpage.
Screenshot:
Now, guys and gals, how about submitting new useful functions for LPut? I'll check this thread periodically.
Thanks. _________________ Geo Massar
Retired Engineer |
|