Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m = peripheral.wrap("back")
- local WIDTH = 16
- local HEIGHT = 16
- local SPEED = 0.1
- if not http then
- print("HTTP must be enabled.")
- return
- end
- local VERSION = "0.1.0"
- print("Lumiere v "..VERSION)
- local apiURL = "http://lakka.kapsi.fi:62096"
- local playerURL = "http://s3.amazonaws.com/MinecraftSkins/"
- local perplist = m.getNamesRemote()
- local min_id = 1000000000000
- for _,name in pairs(perplist) do
- if name:find("glowstone_illuminator") then
- local id = tonumber(name:sub(23,#name))
- if id < min_id then
- min_id = id
- end
- end
- end
- local illuminators = {}
- for i = min_id,min_id+HEIGHT*WIDTH-1 do
- local l = peripheral.wrap("glowstone_illuminator_"..tostring(i))
- table.insert(illuminators,l)
- end
- local index = function(x,y)
- if x%2 == 1 then
- return HEIGHT*(x-1)+(HEIGHT-y)+1
- else
- return HEIGHT*(x-1)+y
- end
- end
- local display = function(image,w,h)
- for r = 1,HEIGHT do
- for c = 1,WIDTH do
- if r <= h and c <= w then
- illuminators[index(c,r)].setColor(tonumber(image[r]:sub(1+8*(c-1),8+8*(c-1)),16))
- else
- illuminators[index(c,r)].setColor(0xFFFFFF)
- end
- end
- end
- end
- -- Returns HEX representation of num
- -- posted in snipplr.com by ukpyr
- function num2hex(num)
- local hexstr = '0123456789abcdef'
- local s = ''
- while num > 0 do
- local mod = math.fmod(num, 16)
- s = string.sub(hexstr, mod+1, mod+1) .. s
- num = math.floor(num / 16)
- end
- if s == '' then
- s = '00'
- elseif #s < 2 then
- s = '0'..s
- end
- return s
- end
- local loadimg = function(name)
- img = {}
- local f = fs.open(name..".txt","r")
- line = f.readLine()
- while line ~= nil do
- table.insert(img,line)
- line = f.readLine()
- end
- f.close()
- return img
- end
- local getImage = function(url,size)
- vars = "url="..url
- vars = vars.."&maxsize="..tostring(size)
- return http.post(apiURL,vars)
- end
- local getGIF = function(url,size)
- vars = "url="..url
- vars = vars.."&maxsize="..tostring(size)
- vars = vars.."&animate=true"
- return http.post(apiURL,vars)
- end
- local splitGIF = function(img)
- frames = {}
- frame = {}
- for _,line in pairs(img) do
- if line == "~" then
- table.insert(frames,frame)
- frame = {}
- else
- table.insert(frame,line)
- end
- end
- return frames
- end
- local displayAnimation = function (frames,w,h)
- for i = 1,#frames do
- display(frames[i],w,h)
- sleep(SPEED)
- end
- end
- local fader = {}
- local run = function(self,steps,dt)
- for i = 1,steps do
- local current = {}
- for r = 1,16 do
- line = ""
- for c = 1,16 do
- local s_px = self.start[r]:sub(1+8*(c-1),8+8*(c-1))
- local e_px = self.final[r]:sub(1+8*(c-1),8+8*(c-1))
- local s_r, s_g, s_b = tonumber(s_px:sub(3,4),16), tonumber(s_px:sub(5,6),16), tonumber(s_px:sub(7,8),16)
- local e_r, e_g, e_b = tonumber(e_px:sub(3,4),16), tonumber(e_px:sub(5,6),16), tonumber(e_px:sub(7,8),16)
- local d_r = ((e_r-s_r)/(steps-1))*(i-1)
- local d_g = ((e_g-s_g)/(steps-1))*(i-1)
- local d_b = ((e_b-s_b)/(steps-1))*(i-1)
- local c_r, c_g, c_b = s_r + d_r, s_g + d_g, s_b + d_b
- line = line.."0x"..num2hex(c_r)..num2hex(c_g)..num2hex(c_b)
- end
- table.insert(current,line)
- end
- display(current)
- sleep(dt)
- end
- end
- fader.run = run
- print "URL:"
- local url = io.read()
- local size = math.max(HEIGHT,WIDTH)
- local resp = getGIF(url,size)
- if not resp then
- print("No response from image server.")
- return
- elseif resp.getResponseCode() ~= 200 then
- print("Error while connecting to server!")
- print("Server response")
- print("Code: "..resp.getResponseCode())
- print("Message:")
- print(resp.readAll())
- return
- end
- local oldSize = resp.readLine()
- local newSize = resp.readLine()
- if oldSize ~= newSize then
- print("Original image size was (w,h): "..oldSize)
- print("New size is (w,h): "..newSize)
- else
- print("Image size is (w,h): "..newSize)
- end
- local sizes = {}
- for word in newSize:gmathc("%w+") do table.insert(sizes, word) end
- local picWidth = tonumber(sizes[1])
- local picHeight = tonumber(sizes[2])
- local img = {}
- local line = resp.readLine()
- while line ~= nil do
- table.insert(img,line)
- line = resp.readLine()
- end
- resp.close()
- while true do
- displayAnimation(splitGIF(img),picWidth,picHeight)
- --sleep(1)
- end
- --display(img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement