Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local gpu = component.gpu
- local matrix = component.induction_matrix
- local me = component.aemultipart
- local oWidth, oHeight = gpu.getResolution()
- local width, height = 124, 40
- gpu.setResolution(width, height)
- local gColor = 1
- local bColor = 2
- local tColor = 3
- local iColor = 4
- gpu.setPaletteColor(1, 0x00FF00)
- gpu.setPaletteColor(2, 0xFF0000)
- gpu.setPaletteColor(3, 0xFFFFFF)
- gpu.setPaletteColor(4, 0x3366FF)
- gpu.setPaletteColor(15, 0x333333)
- gpu.setBackground(15, true)
- gpu.fill(1, 1, width, height, " ")
- --[[
- local item_names = {}
- local original = {}
- do
- local items = me.getAvailableItems()
- for _, itemid in ipairs(items) do
- local fp = itemid.fingerprint
- original[fp.id .. "::" .. fp.dmg] = itemid.size
- end
- end
- ]]
- local function centerWrite(text, y)
- local x = (width - text:len()) / 2
- gpu.set(x, y, text)
- end
- local function endWrite(text, y)
- local x = width - text:len() + 1
- gpu.set(x, y, text)
- end
- local barY = math.floor(height / 2)
- local textY = barY - 2
- local infoY = barY + 2
- local maxpower = matrix.getMaxEnergy()
- local powerUnits = {"J", "KJ", "MJ", "GJ"}
- local function formatPower(j) -- J?
- -- local j = p * 2.5
- local unit = 1
- for i = 1, #powerUnits - 1 do
- if j > 1000 then
- j = j / 1000
- unit = unit + 1
- else
- break
- end
- end
- return string.format("%.2f %s", j, powerUnits[unit])
- end
- local function refresh()
- local power = matrix.getEnergyStored()
- local input = matrix.getInput()
- local output = matrix.getOutput()
- local tWidth = width - 4
- local pWidth = math.ceil((power / maxpower) * tWidth)
- local mWidth = tWidth - pWidth
- gpu.setBackground(1, true)
- gpu.fill(3, barY, pWidth, 1, " ")
- gpu.setBackground(2, true)
- gpu.fill(3 + pWidth, barY, mWidth, 1, " ")
- gpu.setBackground(15, true)
- gpu.setForeground(tColor, true)
- centerWrite("Induction Matrix " .. formatPower(power) .. " / " .. formatPower(maxpower) .. " (" .. math.ceil(power / maxpower * 100) .. "%)", textY)
- gpu.setForeground(iColor, true)
- gpu.fill(1, infoY, width, 1, " ")
- gpu.set(3, infoY, "Input: " .. formatPower(input) .. "/t")
- endWrite("Output: " .. formatPower(output) .. "/t ", infoY)
- --[[
- local items = me.getAvailableItems()
- local removed = {}
- for _, itemid in ipairs(items) do
- end]]
- end
- local suc, err = pcall(function()
- while true do
- local name = event.pull(2)
- if name == "interrupted" then
- break
- end
- refresh()
- end
- end)
- gpu.setBackground(0x000000)
- gpu.setForeground(0xFFFFFF)
- gpu.setResolution(oWidth, oHeight)
- require("term").clear()
- if not suc then
- print("program forcefully interrupted")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement