Skew

ComputerCraft Screen

Apr 26th, 2020
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. -- Config
  2. monitor_side = "left"
  3. monitor_width = 30
  4. modem_side = "top"
  5. modem_channel = 100
  6.  
  7. -- Init modem
  8. modem = peripheral.wrap(modem_side)
  9. modem.open(modem_channel)
  10.  
  11. -- Init monitor
  12. monitor = peripheral.wrap(monitor_side)
  13. monitor.setBackgroundColor(colors.black)
  14. monitor.setTextColor(colors.white)
  15. monitor.clear()
  16. monitor.setCursorPos(1, 1)
  17.  
  18. monitor.write("Waiting for messages")
  19. print("Started. Hold Ctrl+T to terminate.")
  20. while true do
  21.     -- Wait for events
  22.     local ev, side, sch, rch, msg, dist = os.pullEvent("modem_message")
  23.     local result = textutils.unserialize(msg)
  24.  
  25.     -- Draw progress bar
  26.     line = result[1] * 2
  27.     width = (result[3] / result[4]) * monitor_width
  28.     prev = term.redirect(monitor)
  29.     paintutils.drawFilledBox(0, line, monitor_width, line, colors.red)
  30.     paintutils.drawFilledBox(0, line, width, line, colors.green)
  31.     term.redirect(prev)
  32.  
  33.     -- Draw text
  34.     value = math.floor(result[3] * 100.0) / 100.0
  35.     monitor.setBackgroundColor(colors.black)
  36.     monitor.setCursorPos(1, line - 1)
  37.     monitor.clearLine()
  38.     monitor.write(result[2]..": "..value..result[5])
  39. end
Advertisement
Add Comment
Please, Sign In to add comment