Advertisement
dynamicXblue

EnergySend

Mar 24th, 2023 (edited)
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 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. modem.open(9)
  8.  
  9. local powerPerc = 0
  10. local width, height = monitor.getSize()
  11. local wCenter, hCenter = math.floor(width/2)+1, math.floor(height/2)+1
  12. local scale = width/15
  13.  
  14. function monitorSetup(monitor)
  15.     monitor.setTextScale(0.5)
  16.  
  17.     paintutils.drawFilledBox(1, 1, width, height, colors.black)
  18.  
  19.     if width % 2 ~= 0 then
  20.         --Main Sqr
  21.         paintutils.drawBox(wCenter-(4*scale), hCenter+(3*scale), wCenter+(4*scale), hCenter-(3*scale), colors.white)
  22.         --Bat Top
  23.         paintutils.drawBox(wCenter-(2*scale), hCenter-(3*scale), wCenter+(2*scale), hCenter-(4*scale), colors.white)
  24.     else
  25.         --Main Sqr
  26.         paintutils.drawBox(wCenter-(4*scale), hCenter+(3*scale), wCenter+(4*scale), hCenter-(3*scale), colors.white)
  27.         --Bat Top
  28.         paintutils.drawBox(wCenter-(2*scale), hCenter-(3*scale), wCenter+(2*scale+1), hCenter-(4*scale + 1), colors.white)
  29.     end
  30. end
  31.  
  32. function update(h)
  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(6, 9, h)
  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()) * 100
  69.     update(powerPerc)
  70.     os.sleep(1)
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement