Advertisement
Guest User

startup

a guest
Jun 29th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. twerk = peripheral.wrap("left")
  2. monitor = peripheral.wrap("top")
  3. maxEnergy = twerk.getMaxEnergyStored()
  4. width, height = monitor.getSize()
  5.  
  6. function getColor(percentage)
  7.   if percentage < 0.2 then
  8.     return colors.red
  9.   elseif percentage < 0.4 then
  10.     return colors.orange
  11.   elseif percentage < 0.6 then
  12.     return colors.yellow
  13.   elseif percentage < 0.8 then
  14.     return colors.lime
  15.   else
  16.     return colors.green
  17.   end
  18. end
  19.  
  20. function fillMonitor(percentage)
  21.   monitor.setBackgroundColor(colors.black)
  22.   monitor.clear()
  23.   amount = math.floor(percentage*height)
  24.   monitor.setCursorPos(0,height-amount)
  25.   monitor.setBackgroundColor(getColor(percentage))
  26.   for i = 1,amount do
  27.     monitor.setCursorPos(0,height-amount+i)
  28.     monitor.clearLine()
  29.   end
  30. end
  31.  
  32. while true do
  33.   monitor.clear()
  34.   monitor.setCursorPos(1,1)
  35.   energy = twerk.getEnergyStored()/maxEnergy
  36.   fillMonitor(energy)
  37.   sleep(1)
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement