Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local reactor = peripheral.wrap("back")
- local monitor = peripheral.wrap("monitor_0")
- if reactor == nil then
- error("No reactor found")
- end
- if monitor == nil then
- error("No monitor found")
- end
- local energyStored = 0
- local energyProduced = 0
- local energyCapacity = 0
- local fillPercentage = 0
- local batteryWindowBG = window.create(monitor, 2, 2, 5, 10, true)
- local batteryWindowFG = window.create(monitor, 2, 2, 5, 5, true)
- batteryWindowBG.setBackgroundColor(colours.red)
- batteryWindowBG.clear()
- batteryWindowBG.redraw()
- batteryWindowFG.setBackgroundColor(colours.green)
- batteryWindowFG.clear()
- batteryWindowFG.redraw()
- local function round(num, numDecimalPlaces)
- local mult = 10^(numDecimalPlaces or 2)
- return math.floor(num * mult + 0.5) / mult
- end
- local function UpdateReactorStats()
- local stats = reactor.getEnergyStats()
- energyStored = stats["energyStored"]
- energyProduced = stats["energyProducedLastTick"]
- energyCapacity = stats["energyCapacity"]
- if energyStored == 0 then
- fillPercentage = 0
- else
- fillPercentage = energyStored / energyCapacity * 100
- end
- end
- local function ClearScreen()
- term.setBackgroundColor(colours.black)
- term.clear()
- term.setCursorPos(1,1)
- end
- local function ClearMonitor()
- monitor.setBackgroundColor(colours.black)
- monitor.clear()
- monitor.setCursorPos(1,1)
- end
- local function UpdateMonitorStats()
- batteryWindowFG.reposition(2, 2, 5, round(fillPercentage/10, 0))
- batteryWindowBG.redraw()
- batteryWindowFG.redraw()
- --monitor.write(fillPercentage)
- end
- ClearScreen()
- ClearMonitor()
- UpdateReactorStats()
- while true do
- os.sleep(0.2)
- UpdateReactorStats()
- ClearScreen()
- ClearMonitor()
- UpdateMonitorStats()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement