Advertisement
kevorgod

startup

Jan 28th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. local function rgb2hex(r,g,b)
  2.     local t = string.format("0x%02X%02X%02X", r or 0, g or 0, b or 0)
  3.     return tonumber(t)
  4. end
  5. local function getcolor(rat)
  6.   local start_c = {255, 0, 0}
  7.   local end_c = {0, 255, 0}
  8.   local r_dist = end_c[1] - start_c[1]
  9.   local g_dist = end_c[2] - start_c[2]
  10.   local b_dist = end_c[3] - start_c[3]
  11.   local r = start_c[1] + r_dist * rat
  12.   local g = start_c[2] + g_dist * rat
  13.   local b = start_c[3] + b_dist * rat
  14.  
  15.   return rgb2hex(r, g, b)
  16. end
  17. local p = peripheral.wrap("right")
  18. local cell = peripheral.wrap("left")
  19. p.clear()
  20. local ox, oy = 5, 5
  21. local width = 100
  22. local box2 = p.addBox(ox, oy, 50, 14, 0x000000, 0.5)
  23. local box = p.addBox(ox, oy, 0, 14, 0xFFFF00, 0.5)
  24. local energy = p.addText(ox + 6, oy + 3, "", 0xFFFFFF)
  25. while true do
  26.   local ratio = cell.getEnergyStored()/cell.getMaxEnergyStored()
  27.   box.setWidth(width * ratio)
  28.   box2.setWidth(width * (1 - ratio))
  29.   box2.setX(width * ratio)
  30.   box.setColor(getcolor(ratio))
  31.   energy.setText(math.floor(cell.getEnergyStored()) .. " / " .. cell.getMaxEnergyStored())
  32.   os.sleep(0.1)
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement