Posted 18 May 2013 - 06:12 AM
Hello all,
I started developing this little API today.
What it does:
Functions:
The code:
Example code:
thx for reading
-Freack100-
I started developing this little API today.
What it does:
Spoiler
1. It creates a "TMPIMAGE" folder
2.Saves all images from the given table in files called like this: Temp0
3.draws the file
4. Deletes the folder(with the content)
Functions:
Spoiler
TmpImg.startTmp()
--Starts a TmpImg Session (only one can be created an have to be created)
TmpImg.creatTmp(<table>, <lines>)
--creates a new TmpImg with the content of the given table upto to the line you give it
--It returns the Tmp ID
TmpImg.drawTmp(<id>, sX, sY)
--draws the Image at the given position (if you don't entered a position, it draws at 1,1)
TmpImg.endTmp()
--deletes the TMPIMAGES folder
The code:
Spoiler
if not fs.exists("lastTmp") then
local file_handle = fs.open("lastTmp", "w")
file_handle.writeLine("0")
file_handle.close()
end
local lastTmp = fs.open("lastTmp", "r")
lastTmpnum = tonumber(lastTmp.readAll())
lastTmp.close()
end
function reoadTmp()
lastTmp = fs.open("lastTmp", "r")
lastTmpnum = tonumber(lastTmp.readAll())
lastTmp.close()
end
function startTmp()
fs.makeDir("TMPIMAGE")
end
function createTmp(table, sY)
if not type(table) == "table" the
return "Not a table"
else
local file = fs.open("TMPIMAGE/Temp"..tostring(lastTmpnum)+1, "w")
for i = i, sY do
file.writeLine(table[i])
end
file.close()
local editTmp = fs.open("lastTmp", "w")
editTmp.writeLine(lastTmpnum + 1)
editTmp.close()
reloadTmp()
return lastTmpnum
end
end
function drawTmp(id, sX, sY)
local sX = sX or 1
local sY = sY or 1
if not fs.exists("TMPIMAGE/Temp"..tostring(id)) then
else
local id = id
local tmpname = ("TMPIMAGE/Temp"..tostring(id))
tmpIMG = paintutils.loadImage(tmpname)
paintutils.drawImage(tmpIMG, sX, sY)
end
end
function endTmp()
fs.delete("TMPIMAGE")
local lastTmp = fs.open("lastTmp", "w")
lastTmp.writeLine("0")
lastTmp.close()
end
Spoiler
local img = {
[1] = "15346533566433563" --Random color crap
}
os.loadAPI("TmpImg")
TmpImg.startTmp()
local randcol = TmpImg.createTmp(img, 1)
TmpImg.drawTmp(randcol, 1,1)
TmpImg.endTmp()
thx for reading
-Freack100-