Advertisement
Guest User

init.lua

a guest
May 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. function sleep(timeout)
  2.     checkArg(1, timeout, "number", "nil")
  3.     local deadline = computer.uptime() + (timeout or 0)
  4.     repeat
  5.         computer.pullSignal(deadline - computer.uptime())
  6.     until computer.uptime() >= deadline
  7. end
  8.  
  9. function clear()
  10.   local gpu = component.proxy(component.list("gpu")())  
  11.   local oldColor = gpu.getBackground( false )
  12.   local w,h = gpu.getResolution()
  13.   gpu.setBackground( 0x000000, false )
  14.   gpu.fill( 1, 1, w, h, " " )
  15.   gpu.setBackground( oldColor, false )
  16. end
  17.  
  18. function progressBar( label, value, maxVal, show)
  19.   local gpu = component.proxy(component.list("gpu")())
  20.   local oldColor = gpu.getBackground( false )
  21.   gpu.setBackground(0x000000, false)
  22.   gpu.fill( 3, 1, 155, 2, " " )
  23.   w = math.floor( value * (155 / maxVal) )
  24.   p = math.floor( (w / 155) * 100 )
  25.   gpu.set( 3, 1, label .. ": " .. tostring( p ) .. "%" )
  26.   gpu.setBackground( 0x222222, false )
  27.   gpu.fill( 3, 2, 155, 1, " " )
  28.   gpu.setBackground( 0xFF0000, false )
  29.   gpu.fill( 3, 2, w, 1, " " )
  30.   gpu.setBackground( oldColor, false )
  31.   if show then
  32.     local valStr = value .. " units"
  33.     local n = string.len( valStr )
  34.     gpu.set( 158 - n, y, valStr )
  35.   end
  36. end
  37.  
  38. local cells = component.list( "energy_device" )
  39. local gpu = component.proxy(component.list("gpu")())
  40.  
  41. clear()
  42.  
  43. local x,y = gpu.getResolution()
  44. gpu.setResolution(x/2,y/2)
  45.  
  46. while true do
  47.   for address, name in pairs(cells) do
  48.     local cell = component.proxy( address )
  49.     local val = cell.getEnergyStored()
  50.     local max = cell.getMaxEnergyStored()
  51.     progressBar("power", val, max, true)
  52.   end
  53.   sleep(2)
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement