colhaydutu

steampunk electric screen

Apr 19th, 2024
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. local monitor = peripheral.wrap("right")
  2. local battery = peripheral.wrap("top")
  3.  
  4. local function drawBar(x, y, width, fillPercentage)
  5. local fillWidth = math.floor(width * fillPercentage)
  6. term.redirect(monitor)
  7. paintutils.drawLine(2, 2, 12, 2, colors.orange)
  8. paintutils.drawLine(26, 2, 36, 2, colors.orange)
  9. paintutils.drawLine(2, 11, 36, 11, colors.orange)
  10. paintutils.drawLine(2, 11, 2, 5, colors.orange)
  11. paintutils.drawLine(36, 9, 36, 2, colors.orange)
  12. monitor.setBackgroundColor(colors.white)
  13. monitor.setTextColor(colors.black)
  14.  
  15. monitor.setCursorPos(x, y)
  16. monitor.write("[ ")
  17.  
  18. for i = 1, width do
  19. if i <= fillWidth then
  20. monitor.setBackgroundColor(colors.green)
  21. monitor.write(" ")
  22. else
  23. monitor.setBackgroundColor(colors.red)
  24. monitor.write(" ")
  25. end
  26. end
  27.  
  28. monitor.setBackgroundColor(colors.white)
  29. monitor.write(" ] " .. math.floor(fillPercentage * 100) .. "%")
  30. end
  31.  
  32. while true do
  33. local electric = battery.getEnergy()
  34. local capacity = battery.getEnergyCapacity()
  35. local percentFull = (electric / capacity) * 100
  36.  
  37. monitor.clear()
  38. monitor.setCursorPos(5, 2)
  39. monitor.write(" [INFO SCREEN] ")
  40. monitor.setCursorPos(5, 4)
  41. monitor.setBackgroundColor(colors.white)
  42. monitor.setTextColor(colors.orange)
  43.  
  44. monitor.write("Total Electric: " .. electric .. "FE")
  45. monitor.setCursorPos(5, 6)
  46. monitor.write("Total Capacity: " .. capacity .. "FE")
  47.  
  48. drawBar(5, 8, 20, percentFull / 100)
  49.  
  50. os.sleep(1)
  51. end
Add Comment
Please, Sign In to add comment