Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local glass = peripheral.wrap('bottom')
- local power = peripheral.wrap('left')
- -- Glasses
- local startX = 20
- local startY = 5
- local powerID = 'IC2:fluidUuMatter'
- function init()
- if ( checkErrors() ) then
- error('error found')
- end
- glassesLoop()
- end
- function glassesLoop()
- while true do
- glass.clear()
- -- Power
- local powerUsed = power.getEnergyStored()
- local powerMax = power.getMaxEnergyStored()
- local powerPercentage = ( ( powerUsed / powerMax ) * 100 )
- local text = 'POWER: ' .. round(powerPercentage, 2)
- addChargeProgress(startX+1, startY+1, powerID, nil, powerUsed, powerMax, 0.75, 0x7f7f7f, 0.5, 0x4B0082, 1, 0.25, 0.5, 3, text)
- glass.sync()
- sleep(1)
- end
- end
- function checkErrors()
- return false
- end
- function addChargeProgress(x, y, id, meta, amt, max_amt, n_a, s_rgb, s_a, rgb, a, tb_a, e_a, e_int, text)
- local w = getStringWidth(text) + 34
- local h = 18
- glass.addBox(x + 1, y + 1, w - 2, h - 2, rgb, a)
- local i = x + 1 + e_a
- while i <= x + w - 2 do
- glass.addBox(i, y + 1, 1, h - 2, 0x000000, e_a)
- i = i + e_int
- end
- glass.addBox(x + 1, y + 1, w - 2, 3, 0x000000, tb_a)
- glass.addBox(x + 1, y + h - 4, w - 2, 3, 0x000000, tb_a)
- glass.addBox(x, y, w, 1, s_rgb, s_a)
- glass.addBox(x, y + h - 1, w, 1, s_rgb, s_a)
- glass.addBox(x, y + 1, 1, h - 2, s_rgb, s_a)
- glass.addBox(x + w - 1, y + 1, 1, h - 2, s_rgb, s_a)
- local amt_prog = math.ceil(amt / max_amt * w - 2)
- glass.addBox(x + 1 + amt_prog, y + 1, w - 2 - amt_prog, h - 2, 0x000000, n_a)
- glass.addIcon(x + 1, y + 1, id, meta)
- glass.addText(x + 22, y + 5, text)
- end
- function getStringWidth(text)
- local w = 0
- local def = 5
- local w1 = "i!,.:;|"
- local w2 = "'l"
- local w3 = " t"
- local w4 = "*{}()\"<>f"
- local w6 = "~"
- for i = 1, string.len(text) do
- local c = string.sub(text, i, i)
- if string.find(w1, c) ~= nil then
- w = w + 1
- elseif string.find(w2, c) ~= nil then
- w = w + 2
- elseif string.find(w3, c) ~= nil then
- w = w + 3
- elseif string.find(w4, c) ~= nil then
- w = w + 4
- elseif string.find(w6, c) ~= nil then
- w = w + 6
- else
- w = w + 5
- end
- if i < string.len(text) - 1 then
- w = w + 1
- end
- end
- return w
- end
- function round(num, numDecimalPlaces)
- local mult = 10^(numDecimalPlaces or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment