paramus

Generator controller

Mar 10th, 2025 (edited)
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | Gaming | 0 0
  1. -- TODO: Zoom out the graph when it is exceding the top limit
  2. -- * Simply divide per 10 the energy every time the graph overflows?
  3. -- * Set the division manually with a parameter?
  4.  
  5. local Input = peripheral.wrap("top")
  6. local Output = peripheral.wrap("bottom")
  7. local Monitor peripheral.find("monitor")
  8.  
  9. --Parámeters
  10. local MaxX,MaxY
  11. local Zoom = 0
  12.  
  13. --Variables
  14. local EnergyIn = {0,0,10,0,0,10}
  15. local EnergyOut = {0,0,0,0,0,5}
  16. local ValueIn,ValueOut = 0,0
  17.  
  18. function Draw()
  19.     term.setBackgroundColour(colors.white)
  20.     term.clear()
  21.    
  22.     local Increments = MaxX/(#EnergyIn-1)
  23.    
  24.     if (ValueIn>(MaxY+Zoom) or ValueOut>(MaxY+Zoom)) then
  25.         Zoom = Zoom + 10
  26.     end
  27.    
  28.     --Energy history
  29.     local LastPosX = -Increments
  30.     local LastPosY = MaxY
  31.     for i,u in pairs(EnergyIn) do
  32.         paintutils.drawLine(LastPosX+Increments,1, LastPosX+Increments, MaxY, colors.lightGray)
  33.        
  34.         paintutils.drawLine(LastPosX,LastPosY+Zoom, LastPosX+Increments, MaxY-u+Zoom, colors.green)
  35.         LastPosX = LastPosX+Increments
  36.         LastPosY = MaxY-u
  37.     end
  38.    
  39.     LastPosX = -Increments
  40.     LastPosY = MaxY
  41.     for i,u in pairs(EnergyOut) do
  42.         paintutils.drawLine(LastPosX,LastPosY+Zoom, LastPosX+Increments, MaxY-u+Zoom, colors.red)
  43.         LastPosX = LastPosX+Increments
  44.         LastPosY = MaxY-u
  45.     end
  46.    
  47.     --Text
  48.     term.setTextColour(colors.black)
  49.     paintutils.drawPixel(1,1,colors.lime)
  50.     term.setCursorPos(1,1)
  51.     term.write("In: " .. ValueIn .. "FE/t")
  52.     paintutils.drawPixel(1,2,colors.pink)
  53.     term.setCursorPos(1,2)
  54.     term.write("Out: " .. ValueOut .. "FE/t")
  55.     paintutils.drawPixel(1,3,colors.orange)
  56.     term.setCursorPos(1,3)
  57.     term.write("Excess: " .. (ValueIn-ValueOut) .. "FE/t")
  58. end
  59.  
  60. function GetEnergy()
  61.     ValueIn,ValueOut = 0,0
  62.    
  63.     if (Input ~= nil) then
  64.         ValueIn = Input.getTransferRate()
  65.     end
  66.    
  67.     if (Output ~= nil) then
  68.         ValueOut = Output.getTransferRate()
  69.     end
  70.    
  71.     --TODO: remove when finished
  72.     --ValueIn = math.random(100,105)
  73.     --ValueOut = math.random(10,15)
  74.    
  75.     table.remove(EnergyIn, 1)
  76.     table.insert(EnergyIn, ValueIn)
  77.     table.remove(EnergyOut, 1)
  78.     table.insert(EnergyOut, ValueOut)
  79. end
  80.  
  81. -- Main --
  82. if (Monitor ~= nil) then
  83.     term.redirect(Monitor)
  84. end
  85.  
  86. MaxX,MaxY = term.getSize()
  87. while (true) do
  88.     GetEnergy()
  89.     Draw()
  90.     sleep(0.2)
  91. end
Advertisement
Add Comment
Please, Sign In to add comment