 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Tue Sep 06, 2005 3:24 am Post subject: LPut - utility library for Lua Player - 1st release |
|
|
I am attempting to collect utility functions useful for Lua Player coding. Here is the first release.
| Code: | -- 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 _________________ Geo Massar
Retired Engineer
Last edited by KawaGeo on Tue Sep 06, 2005 5:06 am; edited 1 time in total |
|
| Back to top |
|
 |
MikeHaggar
Joined: 18 Jul 2005 Posts: 116
|
Posted: Tue Sep 06, 2005 4:08 am Post subject: |
|
|
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? |
|
| Back to top |
|
 |
KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Tue Sep 06, 2005 5:01 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Dark Killer
Joined: 25 Jan 2005 Posts: 32
|
Posted: Wed Sep 07, 2005 12:21 am Post subject: |
|
|
here's a small function that someone might find usefull: it pauses execution untill all keys are released.
| Code: | 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 |
|
|
| Back to top |
|
 |
Dark Killer
Joined: 25 Jan 2005 Posts: 32
|
Posted: Wed Sep 07, 2005 12:24 am Post subject: |
|
|
| sorry double post |
|
| Back to top |
|
 |
MikeHaggar
Joined: 18 Jul 2005 Posts: 116
|
Posted: Wed Sep 07, 2005 1:09 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|