BrineUtil

Untitled

Jan 30th, 2021 (edited)
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.27 KB | None | 0 0
  1. local canvas = peripheral.call("back","canvas")
  2. rednet.open("top")
  3.  
  4. canvas.clear()
  5.  
  6. local suffixes = {[0]="RF", "KRF", "MRF", "GRF", "TRF", "PRF", "ERF", "ZRF", "YRF"}
  7. local activityIndicator = {[[|]],[[/]],[[-]],[[\]]}
  8. local pos = {1,1}
  9. local scale = 1
  10. local adjustmentRate = 0.0001
  11. local adjustmentCycles = 200
  12.  
  13. local data = {}
  14. local cycles = -1
  15.  
  16. function getData()
  17.     rednet.send(112, "", "CoreStat")
  18.     local _, CoreStatP = rednet.receive("CoreStat",1)
  19.     if CoreStatP then data.CoreStat = CoreStatP end
  20. end
  21.  
  22. function format(I,M,S)
  23.     if M == "RF" then
  24.         local sign
  25.         if I < 0 then
  26.             sign = "-"
  27.             I = 0-I
  28.         elseif I > 0 then
  29.             sign = S and "+" or ""
  30.         else
  31.             return "0RF"
  32.         end
  33.         local log = math.floor(math.log(I)/math.log(1000))
  34.         return sign..string.format("%0.3f",I/1000^log)..suffixes[log]
  35.     elseif M == "time" then
  36.         if I > 315360000000 then
  37.             return "A:Long:Time"
  38.         end
  39.         local S = string.format("%02d",I%60)
  40.         local M = string.format("%02d",(I/60)%60)
  41.         local H = string.format("%02d",(I/3600)%24)
  42.         local D = string.format("%03d",(I/86400)%365)
  43.         local Y = string.format("%04d",I/31536000)
  44.         return Y..":"..D..":"..H..":"..M..":"..S
  45.     end
  46. end
  47.  
  48. local rectangles
  49. rectangles = {
  50.     BG = {
  51.             scalar = {1,1},
  52.             pos = {0,0},
  53.             size = {352, 11},
  54.             color = 0x999999bb
  55.         },
  56.  
  57.     RF = {
  58.             scalar = function()
  59.                 return {data.CoreStat.RF/data.CoreStat.MaxRF, 1}
  60.             end,
  61.             pos = {1,1},
  62.             size = {350, 9},
  63.             color = 0xff0000bb,
  64.          }
  65. }
  66.  
  67. local texts
  68. texts = {
  69.     RF = {
  70.             scale = 1,
  71.             pos = {2,2},
  72.             IO = 0,
  73.             IOM = 0,
  74.             text = function()
  75.                 texts.RF.IO = texts.RF.IO*(1-adjustmentRate) + data.CoreStat.IO*adjustmentRate
  76.                 if cycles%adjustmentCycles == 0 then
  77.                     texts.RF.IO = (texts.RF.IO-texts.RF.IOM*(1-adjustmentRate)^adjustmentCycles)/(1-(1-adjustmentRate)^adjustmentCycles)
  78.                     texts.RF.IOM = texts.RF.IO
  79.                 end
  80.                 local timeRemaining
  81.                 if texts.RF.IO < 0 then
  82.                     timeRemaining = -(data.CoreStat.RF/texts.RF.IOM)/20
  83.                 elseif texts.RF.IO > 0 then
  84.                     timeRemaining = ((data.CoreStat.MaxRF-data.CoreStat.RF)/texts.RF.IOM)/20
  85.                 else
  86.                     timeRemaining = ""
  87.                 end
  88.                 return format(data.CoreStat.RF,"RF").."/"..format(data.CoreStat.MaxRF,"RF")..
  89.                 " ("..string.format("%0.2f",100*data.CoreStat.RF/data.CoreStat.MaxRF).."%) "..
  90.                 format(texts.RF.IOM,"RF",true).."/t "..format(timeRemaining,"time")..
  91.                 "  "..activityIndicator[cycles%#activityIndicator+1]
  92.             end,
  93.             color = 0xffff00ff
  94.         }
  95. }
  96.  
  97. for i, v in pairs(rectangles) do
  98.     v.object = canvas.addRectangle(0,0,0,0,0)
  99. end
  100.  
  101. for i, v in pairs(texts) do
  102.     v.object = canvas.addText({0,0},"",0)
  103. end
  104.  
  105. while true do
  106.     cycles =  cycles+1
  107.     getData()
  108.     for i, v in pairs(rectangles) do
  109.         local scalar, color
  110.         if type(v.scalar) == "function" then
  111.             scalar = v.scalar()
  112.         else
  113.             scalar = v.scalar
  114.         end
  115.  
  116.        
  117.         if type(v.color) == "function" then
  118.             color = v.color()
  119.         else
  120.             color = v.color
  121.         end
  122.        
  123.         v.object.setSize(v.size[1]*scalar[1]*scale, v.size[2]*scalar[2]*scale)
  124.         v.object.setPosition((v.pos[1]+pos[1])*scale, (v.pos[2]+pos[2])*scale)
  125.         v.object.setColor(color)
  126.  
  127.     end
  128.     for i, v in pairs(texts) do
  129.         local text
  130.         if type(v.text) == "function" then
  131.             text = v.text()
  132.         else
  133.             text = v.text
  134.         end
  135.  
  136.         if type(v.color) == "function" then
  137.             color = v.color()
  138.         else
  139.             color = v.color
  140.         end
  141.        
  142.         v.object.setScale(scale*v.scale)
  143.         v.object.setPosition((v.pos[1]+pos[1])*scale, (v.pos[2]+pos[2])*scale)
  144.         v.object.setColor(color)
  145.         v.object.setText(text)
  146.     end
  147. end
Advertisement
Add Comment
Please, Sign In to add comment