Posted 02 January 2017 - 06:39 PM
As some of you might know, you can create images, animations [and text(?)] in npaintpro. in the paintutils API they are two functions that can handle images:
Constructive feedback appreciated.
paintutils.loadImage(imageFilePath) -- loads Image file to Image Table
paintutils.drawImage(imageTable,x,y) -- draws an Image using an Image Table
So, since npaintpro can make animations too I looked through the inter-webs to see if anyone made similar functions for animations. When I found none, I decided to make my own. So here you go people, Happy days.loadAnim
paintutils.loadAnim = function(path)
local frames = {}
local frame = {}
local colorMap = {
[' '] = 0
['0'] = colors.white,
['1'] = colors.orange,
['2'] = colors.magenta,
['3'] = colors.lightBlue,
['4'] = colors.yellow,
['5'] = colors.lime,
['6'] = colors.pink,
['7'] = colors.gray,
['8'] = colors.lightGray,
['9'] = colors.cyan,
['a'] = colors.purple,
['b'] = colors.blue,
['c'] = colors.brown,
['d'] = colors.green,
['e'] = colors.red,
['f'] = colors.black
}
if not fs.exists(path) then
error("file path invalid")
end
local l
local tl = {}
for l in io.lines(path) do
l = f.readLine()
if l == "~" or l == nil then
-- add frame to frames
table.insert(frames,frame)
frame = {}
if l == nil then -- eof
break
end
else
local pixel
for j=1,#l do
-- add char to line
pixel = colorMap[l:lower():sub(j,j)]
table.insert(tl,pixel)
end
-- add line to frame
table.insert(frame,tl)
tl = {}
end
end
return frames
end
drawAnim
paintutils.drawAnim = function(frames,x,y,delay,loop)
x = x or 1
y = y or 1
delay = delay or .25
loop = loop or false
repeat
for i,frame in pairs(frames) do -- iterate through frames
paintutils.drawImage(frame,x,y) -- draw frame
sleep(delay)
end
until not loop
end
Edited on 02 February 2017 - 12:29 PM