Advertisement
Guest User

ogpng.lua

a guest
Dec 2nd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. local gl = require("component").glasses
  2. local png = require("libPNGimage")
  3. local os = require("os") --used to avoid "too long without yielding"
  4.  
  5. local lib = {}
  6.  
  7. function lib.dot(x,y,r,g,b,a)
  8.  r = r or 0
  9.  g = g or 0
  10.  b = b or 1
  11.  a = a or 1
  12.  local d = gl.addDot()
  13.  d.setScale(1)
  14.  d.setPosition(x,y)
  15.  d.setColor(r,g,b)
  16.  d.setAlpha(a)
  17.  return d
  18. end
  19.  
  20. function lib.fillHud(img, xx, yy, cache)
  21.  local dots = {}
  22.  local width, height = img:getSize()
  23.  for x = 1, width do
  24.   for y = 1, height do
  25.    local dot = lib.dot(xx + x - 1, yy + y - 1, img:getPixel(x-1,y-1))
  26.    if cache then table.insert(dots, dot.getID()) end
  27.    os.sleep(0)
  28.   end
  29.  end
  30.  return dots
  31. end
  32.  
  33. function lib.pngToHud(f,x,y,cache)
  34.  checkArg(1, f, "string")
  35.  local fl,err = io.open(f, "rb")
  36.  if not fl then error(err) end
  37.  local img = png.newFromFileHandle(fl)
  38.  return lib.fillHud(img,x or 0, y or 0, cache)
  39. end
  40.  
  41. return lib
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement