Advertisement
FurPuro

accumulator.lua

Jun 9th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.89 KB | None | 0 0
  1. local accum = peripheral.find("modular_accumulator")
  2. local monitor = peripheral.find("monitor")
  3. local mon = {}
  4. local maxCapacity = 40000000
  5. local curState = 0
  6. local szX,szY = monitor.getSize()
  7. local prevEnergy = 0
  8. local speed = 0
  9. local fullPercent = 0
  10.  
  11. mon.monitor,mon.X,mon.Y = monitor,szX,szY
  12.  
  13. local function shorten(num)
  14.     if num >= 1000 and num < 100000 then
  15.         return tostring(math.floor(num/10^2)/10).."K"
  16.     elseif num >= 1000000 and num < 1000000000 then
  17.         return tostring(math.floor(num/10^5)/10).."M"
  18.     end
  19.     return tostring(num)
  20. end
  21.  
  22. local function drawText(x,y,col,text)
  23.     monitor.setBackgroundColor(col)
  24.     monitor.setCursorPos(x,y)
  25.     monitor.write(" ")
  26. end
  27.  
  28. local function fillText(sX,sY,eX,eY,col,text)
  29.     for x=tonumber(sX),tonumber(eX) do
  30.         for y=tonumber(sY),tonumber(eY) do
  31.             drawText(x,y,col,text)
  32.         end
  33.     end
  34. end
  35.  
  36. local function drawPixel(x,y,col)
  37.     drawText(x,y,col," ")
  38. end
  39.  
  40. local function fillPixel(sX,sY,eX,eY,col)
  41.     fillText(sX,sY,eX,eY,col," ")
  42. end
  43.  
  44. local function clear(mon)
  45.     term.clear()
  46.     term.setCursorPos(1,1)
  47.     mon.monitor.setBackgroundColor(colors.black)
  48.     mon.monitor.clear()
  49.     mon.monitor.setCursorPos(1,1)
  50. end
  51.  
  52. local function text()
  53.     while true do
  54.         clear(mon)
  55.  
  56.         monitor.setCursorPos(2,1)
  57.         monitor.write(shorten(maxCapacity))
  58.  
  59.         monitor.setCursorPos(3,szY)
  60.         monitor.write(0)
  61.        
  62.         local spdTxt = "RF/Tick"
  63.        
  64.         monitor.setCursorPos(8,1)
  65.         monitor.write(spdTxt)
  66.        
  67.         monitor.setCursorPos(8+string.len(spdTxt)/2-string.len(tostring(speed))/2,2)
  68.         monitor.write(speed)
  69.  
  70.         local fullTxt = "Full Percent"
  71.        
  72.         monitor.setCursorPos(6,4)
  73.         monitor.write(fullTxt)
  74.        
  75.         monitor.setCursorPos(6+string.len(fullTxt)/2-string.len(tostring(fullPercent).."%")/2,5)
  76.         monitor.write(fullPercent.."%")
  77.  
  78.         fillPixel(2,2,4,szY-1-curState,colors.gray)
  79.        
  80.         if curState>0 then
  81.             fillPixel(2,szY-curState,4,szY-1,colors.red)
  82.         end
  83.  
  84.         monitor.setBackgroundColor(colors.red)
  85.         monitor.setTextColor(colors.orange)
  86.  
  87.         for y=szY-curState,szY-1 do
  88.             monitor.setCursorPos(2,y)
  89.             monitor.write("| |")
  90.         end
  91.        
  92.         monitor.setBackgroundColor(colors.gray)
  93.         monitor.setTextColor(colors.lightGray)
  94.  
  95.         for y=2,szY-1-curState do
  96.             monitor.setCursorPos(2,y)
  97.             monitor.write("| |")
  98.         end
  99.  
  100.         sleep(0)
  101.     end
  102. end
  103.  
  104. local function values()
  105.     while true do
  106.         fullPercent = math.floor(accum.getEnergy()/maxCapacity*100)
  107.         curState = math.floor(fullPercent/10)
  108.  
  109.         speed = accum.getEnergy()-prevEnergy
  110.  
  111.         prevEnergy = accum.getEnergy()
  112.  
  113.         sleep(0.05)
  114.     end
  115. end
  116.  
  117. parallel.waitForAny(text,values)
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement