Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- TODO: Zoom out the graph when it is exceding the top limit
- -- * Simply divide per 10 the energy every time the graph overflows?
- -- * Set the division manually with a parameter?
- local Input = peripheral.wrap("top")
- local Output = peripheral.wrap("bottom")
- local Monitor peripheral.find("monitor")
- --Parámeters
- local MaxX,MaxY
- local Zoom = 0
- --Variables
- local EnergyIn = {0,0,10,0,0,10}
- local EnergyOut = {0,0,0,0,0,5}
- local ValueIn,ValueOut = 0,0
- function Draw()
- term.setBackgroundColour(colors.white)
- term.clear()
- local Increments = MaxX/(#EnergyIn-1)
- if (ValueIn>(MaxY+Zoom) or ValueOut>(MaxY+Zoom)) then
- Zoom = Zoom + 10
- end
- --Energy history
- local LastPosX = -Increments
- local LastPosY = MaxY
- for i,u in pairs(EnergyIn) do
- paintutils.drawLine(LastPosX+Increments,1, LastPosX+Increments, MaxY, colors.lightGray)
- paintutils.drawLine(LastPosX,LastPosY+Zoom, LastPosX+Increments, MaxY-u+Zoom, colors.green)
- LastPosX = LastPosX+Increments
- LastPosY = MaxY-u
- end
- LastPosX = -Increments
- LastPosY = MaxY
- for i,u in pairs(EnergyOut) do
- paintutils.drawLine(LastPosX,LastPosY+Zoom, LastPosX+Increments, MaxY-u+Zoom, colors.red)
- LastPosX = LastPosX+Increments
- LastPosY = MaxY-u
- end
- --Text
- term.setTextColour(colors.black)
- paintutils.drawPixel(1,1,colors.lime)
- term.setCursorPos(1,1)
- term.write("In: " .. ValueIn .. "FE/t")
- paintutils.drawPixel(1,2,colors.pink)
- term.setCursorPos(1,2)
- term.write("Out: " .. ValueOut .. "FE/t")
- paintutils.drawPixel(1,3,colors.orange)
- term.setCursorPos(1,3)
- term.write("Excess: " .. (ValueIn-ValueOut) .. "FE/t")
- end
- function GetEnergy()
- ValueIn,ValueOut = 0,0
- if (Input ~= nil) then
- ValueIn = Input.getTransferRate()
- end
- if (Output ~= nil) then
- ValueOut = Output.getTransferRate()
- end
- --TODO: remove when finished
- --ValueIn = math.random(100,105)
- --ValueOut = math.random(10,15)
- table.remove(EnergyIn, 1)
- table.insert(EnergyIn, ValueIn)
- table.remove(EnergyOut, 1)
- table.insert(EnergyOut, ValueOut)
- end
- -- Main --
- if (Monitor ~= nil) then
- term.redirect(Monitor)
- end
- MaxX,MaxY = term.getSize()
- while (true) do
- GetEnergy()
- Draw()
- sleep(0.2)
- end
Advertisement
Add Comment
Please, Sign In to add comment