Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function rgb2hex(r,g,b)
- local t = string.format("0x%02X%02X%02X", r or 0, g or 0, b or 0)
- return tonumber(t)
- end
- local function getcolor(rat)
- local start_c = {255, 0, 0}
- local end_c = {0, 255, 0}
- local r_dist = end_c[1] - start_c[1]
- local g_dist = end_c[2] - start_c[2]
- local b_dist = end_c[3] - start_c[3]
- local r = start_c[1] + r_dist * rat
- local g = start_c[2] + g_dist * rat
- local b = start_c[3] + b_dist * rat
- return rgb2hex(r, g, b)
- end
- local p = peripheral.wrap("right")
- local cell = peripheral.wrap("left")
- p.clear()
- local ox, oy = 5, 5
- local width = 100
- local box2 = p.addBox(ox, oy, 50, 14, 0x000000, 0.5)
- local box = p.addBox(ox, oy, 0, 14, 0xFFFF00, 0.5)
- local energy = p.addText(ox + 6, oy + 3, "", 0xFFFFFF)
- while true do
- local ratio = cell.getEnergyStored()/cell.getMaxEnergyStored()
- box.setWidth(width * ratio)
- box2.setWidth(width * (1 - ratio))
- box2.setX(width * ratio)
- box.setColor(getcolor(ratio))
- energy.setText(math.floor(cell.getEnergyStored()) .. " / " .. cell.getMaxEnergyStored())
- os.sleep(0.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement