Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. local holoAPI = {}
  2.  
  3. local holow
  4. local holoh
  5. local h = {}
  6.  
  7. local component = require("component")
  8. local term = require("term")
  9.  
  10. function holoAPI.setHolo(hn, hwidth)
  11.   h = {}
  12.   for _, addr in ipairs(hn) do
  13.     local realAddr = component.get(addr)
  14.     table.insert(h, component.proxy(realAddr))
  15.   end
  16.  
  17.   holow = hwidth
  18.   holoh = (#hn)/holow
  19. end
  20.  
  21. function holoAPI.holoClean()
  22.   for i = 1 , #h do
  23.     h[i].clear()
  24.   end
  25. end
  26.  
  27. function holoAPI.holoSetPat(pat)
  28.   for i = 1, #h do
  29.     for j = 1, 3 do
  30.       h[i].setPaletteColor(j, pat[j])
  31.     end
  32.     term.clear()
  33.     term.setCursor(12,1)
  34.     term.write('processing..' .. math.floor(#h/i)*100 .. '%')
  35.     os.sleep()
  36.   end
  37. end
  38.  
  39. function holoAPI.holoCleanWithPat(pat)
  40.   for i = 1, #h do
  41.     h[i].clear()
  42.     for j = 1, 3 do
  43.       h[i].setPaletteColor(j, pat[j])
  44.     end
  45.     os.sleep()
  46.   end
  47. end
  48.  
  49. function holoAPI.draw( x, y, z, c)
  50.   local modx = 48-math.fmod(x-1,48)
  51.   local mody = 32-math.fmod(y-1,32)
  52.  
  53.   local hx   = math.floor((x-1)/48)+1
  54.   local hy   = math.floor((y-1)/32)
  55.  
  56.   h[hy*holow+hx].set(modx, mody, z, c)
  57. end
  58.  
  59.  
  60. function holoAPI.showpic(fileName)
  61.   local img = require( fileName )
  62.   os.sleep()
  63.   holoAPI.holoCleanWithPat( img.pat )
  64.   term.clear()
  65.   local offx = math.floor((holow*48-img.x)/2)
  66.   local offy = math.floor((holoh*32-img.y)/2)
  67.   for y=1, img.y do
  68.     for x=1,img.x do
  69.       holoAPI.draw(x+offx,y+offy,1,img.img[((y-1)*img.x+x)])
  70.     end
  71.   end
  72.  
  73.   local sx = math.floor((50-#img.subtitle/3*2)/2) + 1
  74.   term.clear()
  75.   term.setCursor(sx, 1)
  76.   term.write(img.subtitle)
  77. end
  78.  
  79. return holoAPI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement