Advertisement
BlueMond

glassEnergy

Jan 31st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. local sol = peripheral.wrap("top")
  2. local glass = peripheral.wrap("right")
  3. local batt = peripheral.wrap("back")
  4.  
  5. --for graphing
  6. local posX = 15
  7. local posY = 50
  8. local offsetX = posX+5
  9. local offsetY = posY+5
  10.  
  11. local sizeX = 40
  12. local sizeY = 180
  13. local backX = sizeX-10
  14. local backY = sizeY-10
  15.  
  16.  
  17. local function drawGraph(percent)
  18.     --add frame
  19.     glass.addBox(posX, posY, sizeX, sizeY, 0xFFFFFF, .5)
  20.     --add background
  21.     glass.addBox(offsetX, offsetY, backX, backY, 0x500000, .7)
  22.    
  23.     --determine vertical size of bar
  24.     local size = backY * (percent/100)
  25.     --determine vertical offset of bar
  26.     local offset = offsetY + (backY-size)
  27.    
  28.     --add bar
  29.     glass.addBox(offsetX, offset, backX, size, 0xEB0000, .7)
  30. end
  31.  
  32. local function updateMain()
  33.     local maxE = sol.getMaxEnergyStored()
  34.     local currentE = sol.getEnergyStored()
  35.     local percent
  36.    
  37.     if currentE <= 0 then
  38.         percent = 0
  39.     else
  40.         percent = currentE/maxE * 100
  41.     end
  42.    
  43.     glass.addText(1,40,"Solar Energy", 0xFFFFFF)
  44.     drawGraph(percent)
  45.     print("percent: ".. percent)
  46. end
  47.  
  48. local function updateBackup()
  49.     local maxE = batt.getMaxEnergyStored()
  50.     local currentE = batt.getEnergyStored()
  51.     local percent
  52.    
  53.     if currentE == maxE then
  54.         updateMain()
  55.         return
  56.     else
  57.         percent = currentE/maxE * 100
  58.     end
  59.    
  60.     glass.addText(1,40,"Backup Energy", 0xFFFFFF)
  61.     drawGraph(percent)
  62. end
  63.  
  64. while true do
  65.     sleep()
  66.     glass.clear()
  67.     updateBackup()
  68.     glass.sync()
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement