tima_gt

tde-apis [OpenComputers for BlocksImage format]

Aug 15th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. com = require("component")
  2. gl = com.gpu
  3. write = io.write
  4. getbg = gl.getBackground
  5. setbg = gl.setBackground
  6. getres = gl.getResolution
  7. xfill = gl.fill
  8. function loadImage(imgpath)
  9.   a = {true,true,true,true,true,true,true,true,true,true,true}
  10.   ic = true
  11.   al = true
  12.   f = io.open(imgpath, "r")
  13.   a[1] = tonumber(f:read('*l'))
  14.   al = a[1]*5+1
  15.   for ic = 2, al do
  16.     a[ic] = tonumber(f:read("*l"))
  17.   end
  18.   f:close()
  19.   return a
  20. end
  21. function drawImage(img)
  22.   bgcol = getbg()
  23.   ic = true
  24.   b = 1
  25.   x1c = true
  26.   x2c = true
  27.   y1c = true
  28.   y2c = true
  29.   col = true
  30.   al = img[1]*5+1
  31.   for ic = 2, al do
  32.     if b == 1 then
  33.       b = 2
  34.       x1c = img[ic]
  35.     elseif b == 2 then
  36.       b = 3
  37.       y1c = img[ic]
  38.     elseif b == 3 then
  39.       b = 4
  40.       x2c = img[ic]
  41.     elseif b == 4 then
  42.       b = 5
  43.       y2c = img[ic]
  44.     elseif b == 5 then
  45.       b = 1
  46.       col = img[ic]
  47.       setbg(col)
  48.       xfill(x1c,y1c,x2c-x1c+1,y2c-y1c+1," ")
  49.     end
  50.   end
  51.   setbg(bgcol)
  52. end
Add Comment
Please, Sign In to add comment