New additional function for LPut Utility Library

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

New additional function for LPut Utility Library

Post by KawaGeo »

The new additional function is Shine's rotate(). The editted code is shown:

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
And test program is shown:

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
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:
Image

Now, guys and gals, how about submitting new useful functions for LPut? I'll check this thread periodically.

Thanks.
Geo Massar
Retired Engineer
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

if you want you can add 3 functions from me
  • transpose matrix
    explode string to array
    implode array to string
greets
lumo
PS: you can download the files @ here
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

Thanks, LuMo. I'll look at them.
Geo Massar
Retired Engineer
Dark Killer
Posts: 32
Joined: Tue Jan 25, 2005 3:10 am

Post by Dark Killer »

I along with a few other people posted functions in your other thread that you could include.
Post Reply