Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- --- Generated by EmmyLua(https://github.com/EmmyLua)
- --- Created by User.
- --- DateTime: 08.05.2019 15:06
- ---
- ---▁▂▃▄▅▆▇█▒
- local comp = require("component")
- local event = require("event")
- local gtBattBuf = comp.gt_batterybuffer
- local sides = require("sides")
- local rs = comp.redstone
- local gpu = comp.gpu
- local w, h = gpu.maxResolution()
- local colors = {
- white = 0xffffff,
- orange = 0xff9200,
- magenta = 0xff00ff,
- lightblue = 0x99dbff,
- yellow = 0xffff00,
- lime = 0x00ff00,
- pink = 0xffb6bf,
- gray = 0x787878,
- silver = 0xc3c3c3,
- cyan = 0x00ffff,
- purple = 0x990080,
- blue = 0x0000ff,
- brown = 0x992440,
- green = 0x009200,
- red = 0xff0000,
- black = 0x000000
- }
- --CONFIG BEGIN
- local backgroundColor = 0x26261b
- local mainTextColor = 0x7f1ae5
- local storageColor = colors.red
- local inputColor = colors.green
- local outputColor = colors.blue
- local runningIndicatorColor = 0xbfff00
- local numderLineStorageColor = colors.red
- local numderLineIOColor = colors.cyan
- local backgroundDiagramColor = colors.black
- local redstoneIOControlSide = sides.front
- local head = "MAIN POWER SYSTEM" -- 32 chars max
- --CONFIG END
- local headOffSet = math.modf((32 - string.len(head)) / 2)
- local clear = " "
- local diagramPosX = 1
- local diagramSizeX = w - 4
- local diagramPosY = 11
- local diagramSizeY = h - 11
- local capacity
- local maxEnergyOutput
- local stepSizeCap
- local stepSizeIO
- local int_stepSizeCap
- local int_stepSizeIO
- local partsChar = { " ", "▁", "▂", "▃", "▄", "▅", "▆", "▇" }
- function numPoints(s)
- local x = string.len(s)
- local r = ""
- if (x <= 3) then
- return s
- end
- if (x % 3 == 0) then
- for i = 1, x, 3 do
- r = r .. string.sub(s, i, i + 2) .. "."
- end
- else
- r = r .. string.sub(s, 1, x % 3) .. "."
- for i = 1 + x % 3, x, 3 do
- r = r .. string.sub(s, i, i + 2) .. "."
- end
- end
- return string.sub(r, 1, string.len(r) - 1)
- end
- function mark(n)
- local s = string.sub(numPoints(tostring(n)), 1, 3)
- if n < 1000 and n > 0 then
- s = s .. " "
- elseif n < 1000000 then
- --k
- s = s .. "K"
- elseif n < 1000000000 then
- --m
- s = s .. "M"
- elseif n < 1000000000000 then
- --b
- s = s .. "B"
- elseif n < 1000000000000000 then
- --t
- s = s .. "T"
- else
- s = "err"
- end
- return s
- end
- local m = 0
- function drawNext(storage, input, output)
- if input > maxEnergyOutput then
- input = maxEnergyOutput
- end
- if output > maxEnergyOutput then
- output = maxEnergyOutput
- end
- local i = math.modf(input / stepSizeIO)
- local o = math.modf(output / stepSizeIO)
- gpu.copy(diagramPosX + 1, diagramPosY, diagramSizeX - 1, diagramSizeY, -1, 0)
- gpu.setBackground(backgroundDiagramColor)
- gpu.fill(diagramPosX + diagramSizeX - 1, diagramPosY, 1, diagramSizeY, " ")
- if (i >= o) then
- gpu.setBackground(inputColor)
- gpu.setForeground(outputColor)
- gpu.fill(diagramPosX + diagramSizeX - 1, diagramPosY + diagramSizeY - o, 1, o, "▒")
- gpu.fill(diagramPosX + diagramSizeX - 1, diagramPosY + diagramSizeY - i, 1, i - o, " ")
- gpu.setBackground(backgroundColor)
- gpu.setForeground(mainTextColor)
- else
- gpu.setBackground(inputColor)
- gpu.setForeground(outputColor)
- gpu.fill(diagramPosX + diagramSizeX - 1, diagramPosY + diagramSizeY - i, 1, i, "▒")
- gpu.setBackground(backgroundDiagramColor)
- gpu.fill(diagramPosX + diagramSizeX - 1, diagramPosY + diagramSizeY - o, 1, o - i, "▒")
- gpu.setBackground(backgroundColor)
- gpu.setForeground(mainTextColor)
- end
- if m % 10 == 0 then
- gpu.setForeground(storageColor)
- local st = math.modf(storage / stepSizeCap)
- local p = math.modf((storage - stepSizeCap * st) / (stepSizeCap / 8))
- gpu.copy(34, 1, 160 - 33 - 4, 10, -1, 0)
- gpu.fill(160 - 4, 1, 1, 10, " ")
- gpu.fill(160 - 4, 10 - st + 1, 1, st, "█")
- gpu.set(160 - 4, 10 - st, partsChar[p + 1])
- gpu.setForeground(mainTextColor)
- end
- m = m + 1
- end
- function init()
- local temp = 0
- gpu.setForeground(mainTextColor)
- gpu.setBackground(backgroundColor)
- gpu.fill(1, 1, w, h, ' ')
- gpu.set(headOffSet, 1, head)
- capacity = gtBattBuf.getEUMaxStored()
- for i = 1, 16 do
- temp = gtBattBuf.getMaxBatteryCharge(i)
- if temp ~= nil then
- capacity = capacity + temp
- end
- end
- if maxEnergyOutput == nil then
- maxEnergyOutput = 131072 * 6
- end
- stepSizeCap = capacity / 10
- stepSizeIO = maxEnergyOutput / diagramSizeY
- int_stepSizeCap = math.modf(stepSizeCap)
- int_stepSizeIO = math.modf(stepSizeIO)
- gpu.set(1, 3, string.sub("EU energy max " .. numPoints(tostring(capacity)) .. clear, 1, 32))
- gpu.setForeground(storageColor)
- gpu.set(1, 2, "EU energy store ")
- gpu.setForeground(inputColor)
- gpu.set(1, 4, "EU energy in ")
- gpu.setForeground(outputColor)
- gpu.set(1, 5, "EU energy out ")
- gpu.setForeground(mainTextColor)
- gpu.setBackground(backgroundDiagramColor)
- gpu.fill(diagramPosX, diagramPosY, diagramSizeX, diagramSizeY, " ")
- gpu.setForeground(numderLineStorageColor)
- temp = int_stepSizeCap
- for i = 10, 1, -1 do
- gpu.set(160 - 3, i, mark(temp))
- temp = temp + int_stepSizeCap
- end
- gpu.setBackground(backgroundColor)
- gpu.setForeground(numderLineIOColor)
- temp = int_stepSizeIO
- for i = diagramPosY + diagramSizeY - 1, diagramPosY, -1 do
- gpu.set(diagramSizeX + 1, i, mark(temp))
- temp = temp + int_stepSizeIO
- end
- gpu.setForeground(mainTextColor)
- end
- function blink(flag)
- if flag then
- color = gpu.setBackground(runningIndicatorColor)
- gpu.set(1, 1, " ")
- gpu.setBackground(backgroundColor)
- else
- gpu.set(1, 1, " ")
- end
- return not flag
- end
- function loop()
- local preCapacity = capacity
- local temp = 0
- local flag = true
- local input = 0
- local output = 0
- local n = 0
- local energyStored = 0
- local filter = function(name, ...)
- if name == "touch" then
- return true
- else
- return false
- end
- end
- while true do
- if event.pullFiltered(0.05, filter) == "touch" then
- w, h = gpu.maxResolution()
- if gpu.getViewport() ~= w then
- gpu.setViewport(w, h)
- gpu.set(1, 10, " ")
- else
- gpu.setViewport(32, 10)
- w, h = 32, 10;
- end
- end
- temp = gtBattBuf.getMaxBatteryCharge(n % 16 + 1)
- if temp ~= nil then
- capacity = capacity + temp
- end
- if n % 16 == 0 then
- capacity = capacity + gtBattBuf.getEUMaxStored()
- if n ~= 0 and capacity ~= preCapacity then
- preCapacity = capacity
- stepSizeCap = capacity / 10
- int_stepSizeCap = math.modf(stepSizeCap)
- gpu.setForeground(numderLineStorageColor)
- temp = int_stepSizeCap
- for i = 10, 1, -1 do
- gpu.set(160 - 3, i, mark(temp))
- temp = temp + int_stepSizeCap
- end
- gpu.setForeground(mainTextColor)
- gpu.set(17, 3, string.sub(numPoints(tostring(capacity)) .. clear, 1, 32 - 17))
- end
- end
- input = input + gtBattBuf.getEUInputAverage()
- output = output + gtBattBuf.getEUOutputAverage()
- temp = gtBattBuf.getBatteryCharge(n % 16 + 1)
- if (temp ~= nil) then
- energyStored = energyStored + temp;
- end
- if n % 16 == 0 then
- if n ~= 0 then
- energyStored = energyStored + gtBattBuf.getEUStored()
- gpu.setForeground(storageColor)
- gpu.set(17, 2, string.sub(numPoints(tostring(energyStored)) .. clear, 1, 32 - 17))
- gpu.setForeground(mainTextColor)
- if energyStored / capacity <= 0.05 then
- rs.setOutput(redstoneIOControlSide, 15)
- elseif energyStored / capacity >= 0.98 then
- rs.setOutput(redstoneIOControlSide, 0)
- end
- if rs.getOutput(redstoneIOControlSide) == 0 then
- gpu.set(1, h, "Energy Generation Disable")
- else
- gpu.set(1, h, "Energy Generation Enable ")
- end
- input = math.modf(input / 16)
- output = math.modf(output / 16)
- gpu.setForeground(inputColor)
- gpu.set(17, 4, string.sub(numPoints(tostring(input)) .. clear, 1, 32 - 17))
- gpu.setForeground(outputColor)
- gpu.set(17, 5, string.sub(numPoints(tostring(output)) .. clear, 1, 32 - 17))
- gpu.setForeground(mainTextColor)
- drawNext(energyStored, input, output)
- end
- input = 0
- output = 0
- energyStored = 0
- capacity = 0
- end
- flag = blink(flag)
- n = n + 1
- end
- end
- init()
- loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement