Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This is a program for Computercraft used to display
- -- the power inside a Mekanism Induction Matrix.
- -- It looks best on a 4 wide by 3 high monitor
- -- By: Stekeblad
- -- License: MIT
- -----------------------------------------------------------
- -- config options
- -- digits of precision when displaying numbers
- local precision = 3
- -- variables
- local maxIO = 0
- local maxPow = 0
- local matrix = nil
- local mon = nil
- local powNow
- local inNow
- local outNow
- ------ Functions ------
- -- progress bars
- local function drawInputBar(inputRate)
- progbar.drawVerticalBar(2, 2, 3, 13,
- inputRate/maxIO,
- colors.lime, true, colors.gray)
- end
- local function drawOutputBar(outputRate)
- progbar.drawVerticalBar(14, 2, 3, 13,
- outputRate/maxIO,
- colors.red, true, colors.gray)
- end
- local function drawMainBar(stored)
- progbar.drawVerticalBar(30, 2, 8, 13,
- stored/maxPow, colors.blue,
- true, colors.gray)
- end
- -- conversion and formatting
- local function scaleNumber(number)
- local numLog = math.floor(math.log(number))
- if (numLog < precision) then
- return number
- end
- number = math.floor(number)
- local asText = tostring(number)
- local revText = ""
- local counter = 0
- local magnitude = 0
- for chara in string.gmatch(string.reverse(asText), ".") do
- if counter % 3 == 0 and counter ~= 0 then
- revText = revText .. ","
- magnitude = magnitude + 1
- end
- revText = revText .. chara
- counter = counter + 1
- end
- asText = string.reverse(revText)
- local commaIndex = string.find(asText, ",")
- if commaIndex == nil then
- if counter <= precision then
- return asText -- no comma and fits in precision
- end
- elseif commaIndex == precision + 1 then
- asText = string.sub(asText, precision) -- missing suffix at this point
- else
- -- adjust asText to precision
- local i = 0
- local newText = ""
- for chara in asText:gmatch(".") do
- newText = newText .. chara
- if chara ~= "," then
- i = i + 1
- end
- if i == precision then break end
- end
- asText = newText
- end
- if magnitude == 0 then
- return asText
- elseif magnitude == 1 then
- return asText .. "k"
- elseif magnitude == 2 then
- return asText .. "M"
- elseif magnitude == 3 then
- return asText .. "G"
- elseif magnitude == 4 then
- return asText .. "T"
- elseif magnitude == 5 then
- return asText .. "P"
- elseif magnitude == 6 then
- return asText .. "E"
- end
- end
- ------ init --------
- if not progbar then
- os.loadAPI("progbar.lua")
- if not progbar then
- error("Could not load progbar.lua API, get it with this pastebin code: gVWb750w")
- end
- end
- matrix = peripheral.find("Induction Matrix")
- if matrix == nil then
- error("Could not find a Mekanism Induction Matrix")
- end
- mon = peripheral.find("monitor")
- if mon == nil then
- error("Could not find a monitor, please connect one")
- end
- mon.setTextScale(1)
- local oldterm = term.redirect(mon)
- maxPow = matrix.getMaxEnergy() /2.5 --J --> RF
- maxIO = matrix.getTransferCap() /2.5 -- J --> RF
- ------ Main loop -----
- while true do
- powNow = matrix.getEnergy() /2.5 -- J --> RF
- inNow = matrix.getInput() /2.5 -- J --> RF
- outNow = matrix.getOutput() /2.5 -- J --> RF
- term.clear()
- drawInputBar(inNow)
- drawOutputBar(outNow)
- drawMainBar(powNow)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(7, 3)
- print(scaleNumber(maxIO))
- term.setCursorPos(31, 17)
- print(scaleNumber(powNow))
- term.setCursorPos(7, 7)
- term.setTextColor(colors.green)
- print(scaleNumber(inNow))
- term.setCursorPos(7, 11)
- term.setTextColor(colors.red)
- print(scaleNumber(outNow))
- sleep(3)
- end
- --term.redirect(oldterm)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement