Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.find("monitor")
- if not mon then
- print("Aucun monitor détecté")
- return
- end
- rednet.open("right") -- adapte à ton modem
- mon.setTextScale(0.5)
- local w, h = mon.getSize()
- function getBarColor(percent)
- if percent < 0.3 then return colors.red
- elseif percent < 0.6 then return colors.orange
- else return colors.lime end
- end
- function drawBar(x, y, percent, width)
- local filled = math.floor(percent * width)
- local empty = width - filled
- mon.setCursorPos(x, y)
- mon.setBackgroundColor(getBarColor(percent))
- mon.write(string.rep(" ", filled))
- mon.setBackgroundColor(colors.gray)
- mon.write(string.rep(" ", empty))
- mon.setBackgroundColor(colors.black)
- end
- function clearLine(y)
- mon.setCursorPos(1, y)
- mon.setBackgroundColor(colors.black)
- mon.write(string.rep(" ", w))
- end
- while true do
- local id, data = rednet.receive("energy_display")
- if data then
- mon.setBackgroundColor(colors.black)
- for i, cell in ipairs(data.cells) do
- local y = i * 2 - 1
- clearLine(y)
- local nomCellule = string.format("Cellule %-2d", i)
- mon.setCursorPos(1, y)
- mon.setTextColor(colors.yellow)
- mon.write(string.format("[%s]", nomCellule))
- drawBar(10, y, cell.percent, 20)
- mon.setCursorPos(32, y)
- mon.setTextColor(colors.white)
- mon.write(string.format("%3d%%", cell.percent * 100))
- mon.setCursorPos(40, y)
- if cell.delta > 0 then
- mon.setTextColor(colors.lime)
- elseif cell.delta < 0 then
- mon.setTextColor(colors.red)
- else
- mon.setTextColor(colors.gray)
- end
- mon.write(string.format("%+4d RF/t ", cell.delta))
- end
- -- Affichage global
- local globalBarY = h - 1
- clearLine(globalBarY)
- clearLine(h)
- drawBar(10, globalBarY, data.globalPercent, 20)
- mon.setCursorPos(1, globalBarY)
- mon.setTextColor(colors.cyan)
- mon.write("[GLOBAL]")
- mon.setCursorPos(32, globalBarY)
- mon.setTextColor(colors.white)
- mon.write(string.format("%3d%%", data.globalPercent * 100))
- mon.setCursorPos(1, h)
- mon.setTextColor(colors.lightGray)
- mon.write("Estimation : " .. data.estTime .. " ")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement