Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Running a project contained in an Image - Proof of concept

BriarfoxBriarfox Mod
edited July 2013 in General Posts: 1,542

I'm still not sure on the practical use but this will load an image from dropbox and execute the code. The image containes Life Sim by @ipad41001



--# ByteImage ByteImage = class() function ByteImage:init() end function ByteImage:dumpB(f) local binary = string.dump(f) local formatted_binary = "" for i = 1, string.len(binary) do local dec, _ = ("\\%3d"):format(binary:sub(i, i):byte()):gsub(' ', '0') formatted_binary = formatted_binary .. dec end return formatted_binary end function ByteImage:dump(f) local binary = string.dump(f) local formatted_binary = "" for i = 1, string.len(binary) do local dec, _ = ("%3d"):format(binary:sub(i, i):byte()):gsub(' ', '0') formatted_binary = formatted_binary .. dec end return formatted_binary end function ByteImage:createImage(f,name) local byteStr = ByteImage:dump(f) local col = 100 local byteCount = #byteStr/3 local row = math.ceil(byteCount / col) print (byteCount) local img = image(col,row) local ist = 1 local ien = 3 for i=1,row do for j=1,col do local r = tonumber(byteStr:sub(ist,ien)) ist = ien +1 ien = ien + 3 if r == nil then r = 000 end local g = tonumber(byteStr:sub(ist,ien)) ist = ien +1 ien = ien + 3 if g == nil then g = 000 end local b = tonumber(byteStr:sub(ist,ien)) ist = ien +1 ien = ien + 3 if b == nil then b = 000 end img:set(j,i,r,g,b,255) end end saveImage("Dropbox:"..name,img) end function ByteImage:readImage(img) -- local tststr = "" local im = readImage(img) local byteCount = 880 local byteItr = 1 local str = "tststr='" local w,h = im.width, im.height for i =1,h do for j=1,w do --[[ local r,g,b = im:get(j,i) if byteItr <= byteCount then r = string.format("%03d",r) byteItr = byteItr + 1 end if byteItr <= byteCount then g = string.format("%03d",g) byteItr = byteItr + 1 end if byteItr <= byteCount then b = string.format("%03d",b) byteItr = byteItr + 1 end if byteItr <= byteCount then str = str.."\\" .. r.."\\"..g.."\\"..b end --]] local r,g,b = im:get(j,i) r = string.format("%03d",r) g = string.format("%03d",g) b = string.format("%03d",b) str = str.."\\" .. r.."\\"..g.."\\"..b end end str = str .. "'" loadstring(str)() --print("test: "..tststr) local f = loadstring(tststr) return f --assert(loadstring(str)) end --# Main -- test -- Use this function to perform your initial setup function setup() link = "https://dl.dropboxusercontent.com/s/ksxtu4wqbfywmt8/Photo Jul 15, 2 49 23 PM.png?token_hash=AAEvPUnkTYp4FoONBcdMaaCiKCSiStEv59RJeP9T32NxsQ&amp;dl=1" http.request(link,callback) end -- This function gets called once every frame function draw() -- This sets a dark background color background(40, 40, 50) text("Loading Image",WIDTH/2,HEIGHT/2) end function callback(d) img = d saveImage("Documents:Life07162013",img) test3 = ByteImage:readImage("Documents:Life07162013") --load code in image test3() --Run code in imapge setup1() -- run images setup draw = draw1 --images draw end

Comments

Sign In or Register to comment.