Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Setup
- os.loadAPI("touchpoint") --Touchpoinz API by Lyqyd
- mon = peripheral.find("monitor")
- mat = peripheral.find("peripheralProxy:inductionMatrix")
- --Round Function
- function round(float)
- local int, part = math.modf(float)
- if float == math.abs(float) and part >= .5 then return int+1
- elseif part <= -.5 then return int-1
- end
- return int
- end
- --Round with 2 Decimals Function
- function roundD(exact, quantum)
- local quant,frac = math.modf(exact/quantum)
- return quantum * (quant + (frac > 0.5 and 1 or 0))
- end
- --Conversion Function
- function conversion(exact, text)
- local units = {"", "K", "M", "G", "T", "P", "E", "Z", "Y"}
- local pot = 1
- local absExact = math.abs(exact)
- while absExact >= (1000^pot) do
- pot = pot + 1
- end
- local out = tostring(roundD(exact / (1000^(pot - 1)), 0.1))
- if text then
- out = out .. " " .. units[pot]
- end
- return out
- end
- --Draw Function
- function draw(xmin, xmax, ymin, ymax, c)
- mon.setBackgroundColor(c)
- mon.setCursorPos(xmin, ymin)
- if xmax ~= 1 then
- for i = 1, xmax, 1 do
- mon.write(" ")
- mon.setCursorPos(xmin+i, ymin)
- end
- end
- if ymax ~= 1 then
- for k = 1, ymax, 1 do
- mon.write(" ")
- mon.setCursorPos(xmin, ymin+k)
- end
- end
- mon.setBackgroundColor(32768)
- end
- --DrawBar Function
- function drawBar(xmin, xmax, y, r, c)
- for i=1, r, 1 do
- draw(xmin, xmax, y+i-1, 1, c)
- end
- end
- --DrawDiagrams Function
- function drawDiagrams()
- local energy = round((mat.getEnergyFilledPercentage())*29)
- local input = round((mat.getLastInput()/mat.getTransferCap())*29)
- local output = round((mat.getLastOutput()/mat.getTransferCap())*29)
- drawBar(4, energy, 4, 3, 8)
- drawBar(4, input, 11, 2, 32)
- drawBar(4, output, 15, 2, 32)
- end
- --Draw Visuals Function
- function drawVisuals()
- --Frame Induction Matrix
- draw(2, 2, 2, 1, 128)
- draw(22, 13, 2, 1, 128)
- draw(2, 1, 2, 17, 128)
- draw(2, 33, 18, 1, 128)
- draw(34, 1, 2, 17, 128)
- draw(2, 33, 8, 1, 128)
- mon.setCursorPos(5,2)
- mon.write("Induction Matrix")
- --Frame SPS Control
- draw(36, 2, 2, 1, 128)
- draw(36, 1, 2, 9, 128)
- draw(49, 1, 2, 9, 128)
- draw(36, 13, 10, 1, 128)
- draw(43, 6, 2, 1, 128)
- mon.setCursorPos(39,2)
- mon.write("SPS")
- --Frame Stats
- draw(36, 1, 12, 7, 128)
- draw(49, 1, 12, 7, 128)
- draw(36, 13, 18, 1, 128)
- draw(36, 2, 12, 1, 128)
- draw(45, 4, 12, 1, 128)
- mon.setCursorPos(39,12)
- mon.write("Stats")
- --energyBar
- drawBar(4, 29, 4, 3, 256)
- --inputBar
- drawBar(4, 29, 11, 2, 256)
- mon.setCursorPos(4,10)
- mon.write("Input:")
- --outputBar
- drawBar(4, 29, 15, 2, 256)
- mon.setCursorPos(4,14)
- mon.write("Output:")
- end
- --DrawStats Function
- function drawStats()
- local cells = mat.getInstalledCells()
- local prov = mat.getInstalledProviders()
- local maxEnergy = conversion(mat.getMaxEnergy(), false)
- local energyStored = conversion(mat.getEnergy(), true)
- local energyInput = conversion(mat.getLastInput(), true)
- local energyOutput = conversion(mat.getLastOutput(), true)
- mon.setCursorPos(38,14)
- mon.write("Cells: "..cells)
- mon.setCursorPos(38,15)
- mon.write("Prov: "..prov)
- mon.setCursorPos(38,16)
- mon.write("Cap: "..maxEnergy)
- mon.setCursorPos(23,2)
- mon.write(" "..energyStored.."RF ")
- mon.setCursorPos(10,10)
- mon.write(" "..energyInput.."RF/t ")
- mon.setCursorPos(11,14)
- mon.write(" "..energyOutput.."RF/t ")
- end
- --Buttons
- local t = touchpoint.new("top")
- t:add("Inactive", nil, 38, 4, 47, 8, colors.red, colors.lime)
- --Draw
- t:draw()
- drawVisuals()
- drawDiagrams()
- drawStats()
- --Timer
- local lastTime = 6
- --Loop
- while true do
- local event, p1 = t:handleEvents(os.pullEvent())
- if event == "button_click" then
- t:toggleButton(p1)
- if p1 == "Inactive" then
- t:rename("Inactive", "Active")
- rs.setOutput("left", true)
- elseif p1 == "Active" then
- t:rename("Active", "Inactive")
- rs.setOutput("left",false)
- end
- drawVisuals()
- drawDiagrams()
- drawStats()
- end
- if os.clock() - lastTime >= 5 then
- mon.clear()
- t:draw()
- drawVisuals()
- drawDiagrams()
- drawStats()
- lastTime = os.clock()
- end
- end
Add Comment
Please, Sign In to add comment