Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sleep(timeout)
- checkArg(1, timeout, "number", "nil")
- local deadline = computer.uptime() + (timeout or 0)
- repeat
- computer.pullSignal(deadline - computer.uptime())
- until computer.uptime() >= deadline
- end
- function clear()
- local gpu = component.proxy(component.list("gpu")())
- local oldColor = gpu.getBackground( false )
- local w,h = gpu.getResolution()
- gpu.setBackground( 0x000000, false )
- gpu.fill( 1, 1, w, h, " " )
- gpu.setBackground( oldColor, false )
- end
- function progressBar( label, value, maxVal, show)
- local gpu = component.proxy(component.list("gpu")())
- local oldColor = gpu.getBackground( false )
- gpu.setBackground(0x000000, false)
- gpu.fill( 3, 1, 155, 2, " " )
- w = math.floor( value * (155 / maxVal) )
- p = math.floor( (w / 155) * 100 )
- gpu.set( 3, 1, label .. ": " .. tostring( p ) .. "%" )
- gpu.setBackground( 0x222222, false )
- gpu.fill( 3, 2, 155, 1, " " )
- gpu.setBackground( 0xFF0000, false )
- gpu.fill( 3, 2, w, 1, " " )
- gpu.setBackground( oldColor, false )
- if show then
- local valStr = value .. " units"
- local n = string.len( valStr )
- gpu.set( 158 - n, y, valStr )
- end
- end
- local cells = component.list( "energy_device" )
- local gpu = component.proxy(component.list("gpu")())
- clear()
- local x,y = gpu.getResolution()
- gpu.setResolution(x/2,y/2)
- while true do
- for address, name in pairs(cells) do
- local cell = component.proxy( address )
- local val = cell.getEnergyStored()
- local max = cell.getMaxEnergyStored()
- progressBar("power", val, max, true)
- end
- sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement