dynamicXblue

EnergySend

Mar 24th, 2023 (edited)
1,103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.10 KB | Gaming | 0 0
  1. os.sleep(1)
  2.  
  3. local monitor = peripheral.find("monitor")
  4. local source = peripheral.wrap("back")
  5. local modem = peripheral.find("modem")
  6.  
  7. local powerPerc = 0
  8. local width, height = monitor.getSize()
  9. local wCenter, hCenter = math.floor(width/2)+1, math.floor(height/2)+1
  10. local scale = width/15
  11.  
  12. function monitorSetup(monitor)
  13.     monitor.setTextScale(0.5)
  14.  
  15.     paintutils.drawFilledBox(1, 1, width, height, colors.black)
  16.  
  17.     if width % 2 ~= 0 then
  18.         --Main Sqr
  19.         paintutils.drawBox(wCenter-(4*scale), hCenter+(3*scale), wCenter+(4*scale), hCenter-(3*scale), colors.white)
  20.         --Bat Top
  21.         paintutils.drawBox(wCenter-(2*scale), hCenter-(3*scale), wCenter+(2*scale), hCenter-(4*scale), colors.white)
  22.     else
  23.         --Main Sqr
  24.         paintutils.drawBox(wCenter-(4*scale), hCenter+(3*scale), wCenter+(4*scale), hCenter-(3*scale), colors.white)
  25.         --Bat Top
  26.         paintutils.drawBox(wCenter-(2*scale), hCenter-(3*scale), wCenter+(2*scale+1), hCenter-(4*scale + 1), colors.white)
  27.     end
  28. end
  29.  
  30. function update(h)
  31.  
  32.     h = h * 100
  33.  
  34.     if monitor ~= nil then
  35.         local y = hCenter+(3*scale-1)
  36.         local nbars = (4*scale-1) + (4*scale-1) - scale
  37.  
  38.         local color
  39.         paintutils.drawFilledBox(wCenter-(4*scale-1), hCenter+(3*scale-1), wCenter+(4*scale-1), hCenter-(3*scale-1), colors.black)
  40.  
  41.         if h > 66 then
  42.             color = colors.green
  43.         elseif h > 33 then
  44.             color = colors.orange
  45.         else
  46.             color = colors.red
  47.         end
  48.  
  49.         if h ~= 0 then
  50.             if width % 2 ~= 0 then
  51.                 paintutils.drawFilledBox(wCenter-(4*scale-1), y, wCenter+(4*scale-1), y-math.floor(nbars*h/100)+1, color)
  52.             else
  53.                 paintutils.drawFilledBox(wCenter-(4*scale-1), y, wCenter+(4*scale-1), y-math.floor(nbars*h/100)+1, color)
  54.             end
  55.         end
  56.     end
  57.  
  58.     modem.transmit(1, 2, h/100)
  59.    
  60. end
  61.  
  62. if monitor ~= nil then
  63.     term.redirect(monitor)
  64.     monitorSetup(monitor)
  65. end
  66.  
  67. while true do
  68.     powerPerc = (source.getEnergy() / source.getMaxEnergy())
  69.     update(powerPerc)
  70.     os.sleep(1)
  71. end
Advertisement
Add Comment
Please, Sign In to add comment