Advertisement
Flawedspirit

ComputerCraft Bar API

Mar 28th, 2014
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.69 KB | None | 0 0
  1. local mon = peripheral.wrap("top")
  2. local bgCol = colors.black
  3.  
  4. function draw(val, x, y)
  5.   local color
  6.   mon.setBackgroundColor(bgCol)
  7.   mon.clearLine()
  8.   mon.setCursorPos(x, y)
  9.  
  10.   if val >= 10 then
  11.     color = colors.lightBlue
  12.   elseif val >= 7 then
  13.     color = colors.lime
  14.   elseif val >= 4 then
  15.     color = colors.yellow
  16.   elseif val >= 1 then
  17.     color = colors.orange
  18.   elseif val == 0 then
  19.     color = colors.red
  20.   else color = colors.gray
  21.   end
  22.  
  23.   for i = 1, val + 2 do
  24.     mon.setBackgroundColor(color)
  25.     mon.write(" ") --This is the segment of bar itself
  26.     mon.setCursorPos(i + 1, y)
  27.   end
  28. end
  29.  
  30. function drawBar(val, x, y)
  31.   draw(math.floor(val * 0.1), x, y)
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement