LPut - utility library for Lua Player - 1st release

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

LPut - utility library for Lua Player - 1st release

Post by KawaGeo »

I am attempting to collect utility functions useful for Lua Player coding. Here is the first release.

Code: Select all

-- LPut.lua editted by Geo Massar, 2005 (aka KawaGeo)
-- Ver. 0.1 - first release

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
  local PI2 = math.pi * 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

function Image:magnify(mag)
  mag = mag or 2           -- 2 times in size by default
  local w = self:width()  
  local h = self:height()
  local result = Image.createEmpty(mag*w, mag*h)
  for x = 0, w-1 do
    for y = 0, h-1 do
      result:fillRect(mag*x, mag*y, mag,mag, self:pixel(x,y))
    end
  end
  return result
end

function Image:caption(x,y, text, color, mag)
  mag = mag or 1
  local w = string.len(text)
  local temp = Image.createEmpty(8 * w, 8)
  temp:print(0,0, text, color)
  if mag > 1 then 
    temp = temp:magnify(mag)
  end
  self:blit(x,y, temp)
end

--------------------  Credits ---------------------

-- Nils    for math.round             Aug 2005
-- KawaGeo for Image:drawEllipse,     Sep 2005
-- MikeHaggar  for Image:magnify (formerly, resize)
-- KawaGeo for Image:caption,         Sep 2005
--
Download: You can get the library source there.

Anyone has a good utility or any idea, please let me know. I will add them in the next release.

Thanks.

Editted 9/5/2005
Last edited by KawaGeo on Tue Sep 06, 2005 5:06 am, edited 1 time in total.
Geo Massar
Retired Engineer
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

Hmm... If you've taken the Image:magnify function from one of my games, then I'm the one who made it.

Maybe you should add image rotate too?
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

Noted. Thanks, Mike.

Will you pls direct me to your image rotate function? I would be happy to add it to LPut library.
Geo Massar
Retired Engineer
Dark Killer
Posts: 32
Joined: Tue Jan 25, 2005 3:10 am

Post by Dark Killer »

here's a small function that someone might find usefull: it pauses execution untill all keys are released.

Code: Select all

function Controls.waitpadup()
	pad=Controls.read()
	while pad:select() or pad:start() or pad:up() or pad:right() or pad:down() or pad:left() or pad:l() or pad:r() or pad:triangle() or pad:circle() or pad:cross() or pad:square() do
		screen.waitVblankStart()
		pad=Controls.read()
	end
end
Dark Killer
Posts: 32
Joined: Tue Jan 25, 2005 3:10 am

Post by Dark Killer »

sorry double post
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

check one of my games (except Dr. Mario)... in font.lua there's the rotate function. The rotate function is made by shine, not me though.
Post Reply