Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.wrap("right")
- local battery = peripheral.wrap("top")
- local function drawBar(x, y, width, fillPercentage)
- local fillWidth = math.floor(width * fillPercentage)
- term.redirect(monitor)
- paintutils.drawLine(2, 2, 12, 2, colors.orange)
- paintutils.drawLine(26, 2, 36, 2, colors.orange)
- paintutils.drawLine(2, 11, 36, 11, colors.orange)
- paintutils.drawLine(2, 11, 2, 5, colors.orange)
- paintutils.drawLine(36, 9, 36, 2, colors.orange)
- monitor.setBackgroundColor(colors.white)
- monitor.setTextColor(colors.black)
- monitor.setCursorPos(x, y)
- monitor.write("[ ")
- for i = 1, width do
- if i <= fillWidth then
- monitor.setBackgroundColor(colors.green)
- monitor.write(" ")
- else
- monitor.setBackgroundColor(colors.red)
- monitor.write(" ")
- end
- end
- monitor.setBackgroundColor(colors.white)
- monitor.write(" ] " .. math.floor(fillPercentage * 100) .. "%")
- end
- while true do
- local electric = battery.getEnergy()
- local capacity = battery.getEnergyCapacity()
- local percentFull = (electric / capacity) * 100
- monitor.clear()
- monitor.setCursorPos(5, 2)
- monitor.write(" [INFO SCREEN] ")
- monitor.setCursorPos(5, 4)
- monitor.setBackgroundColor(colors.white)
- monitor.setTextColor(colors.orange)
- monitor.write("Total Electric: " .. electric .. "FE")
- monitor.setCursorPos(5, 6)
- monitor.write("Total Capacity: " .. capacity .. "FE")
- drawBar(5, 8, 20, percentFull / 100)
- os.sleep(1)
- end
Add Comment
Please, Sign In to add comment