Flawedspirit icon

ComputerCraft Bar API

Flawedspirit | PRO | 03/28/14 06:26:24 AM UTC | 0 ⭐ | 239 👁️ | Never ⏰ | []
Lua |

690 B

|

None

|

0 👍

/

0 👎

local mon = peripheral.wrap("top")
local bgCol = colors.black
 
function draw(val, x, y)
  local color
  mon.setBackgroundColor(bgCol)
  mon.clearLine()
  mon.setCursorPos(x, y)
 
  if val >= 10 then
    color = colors.lightBlue
  elseif val >= 7 then
    color = colors.lime
  elseif val >= 4 then
    color = colors.yellow
  elseif val >= 1 then
    color = colors.orange
  elseif val == 0 then
    color = colors.red
  else color = colors.gray
  end
 
  for i = 1, val + 2 do
    mon.setBackgroundColor(color)
    mon.write(" ") --This is the segment of bar itself
    mon.setCursorPos(i + 1, y)
  end
end
 
function drawBar(val, x, y)
  draw(math.floor(val * 0.1), x, y)
end

Comments