Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local canvas = peripheral.call("back","canvas")
- rednet.open("top")
- canvas.clear()
- local suffixes = {[0]="RF", "KRF", "MRF", "GRF", "TRF", "PRF", "ERF", "ZRF", "YRF"}
- local activityIndicator = {[[|]],[[/]],[[-]],[[\]]}
- local pos = {1,1}
- local scale = 1
- local adjustmentRate = 0.0001
- local adjustmentCycles = 200
- local data = {}
- local cycles = -1
- function getData()
- rednet.send(112, "", "CoreStat")
- local _, CoreStatP = rednet.receive("CoreStat",1)
- if CoreStatP then data.CoreStat = CoreStatP end
- end
- function format(I,M,S)
- if M == "RF" then
- local sign
- if I < 0 then
- sign = "-"
- I = 0-I
- elseif I > 0 then
- sign = S and "+" or ""
- else
- return "0RF"
- end
- local log = math.floor(math.log(I)/math.log(1000))
- return sign..string.format("%0.3f",I/1000^log)..suffixes[log]
- elseif M == "time" then
- if I > 315360000000 then
- return "A:Long:Time"
- end
- local S = string.format("%02d",I%60)
- local M = string.format("%02d",(I/60)%60)
- local H = string.format("%02d",(I/3600)%24)
- local D = string.format("%03d",(I/86400)%365)
- local Y = string.format("%04d",I/31536000)
- return Y..":"..D..":"..H..":"..M..":"..S
- end
- end
- local rectangles
- rectangles = {
- BG = {
- scalar = {1,1},
- pos = {0,0},
- size = {352, 11},
- color = 0x999999bb
- },
- RF = {
- scalar = function()
- return {data.CoreStat.RF/data.CoreStat.MaxRF, 1}
- end,
- pos = {1,1},
- size = {350, 9},
- color = 0xff0000bb,
- }
- }
- local texts
- texts = {
- RF = {
- scale = 1,
- pos = {2,2},
- IO = 0,
- IOM = 0,
- text = function()
- texts.RF.IO = texts.RF.IO*(1-adjustmentRate) + data.CoreStat.IO*adjustmentRate
- if cycles%adjustmentCycles == 0 then
- texts.RF.IO = (texts.RF.IO-texts.RF.IOM*(1-adjustmentRate)^adjustmentCycles)/(1-(1-adjustmentRate)^adjustmentCycles)
- texts.RF.IOM = texts.RF.IO
- end
- local timeRemaining
- if texts.RF.IO < 0 then
- timeRemaining = -(data.CoreStat.RF/texts.RF.IOM)/20
- elseif texts.RF.IO > 0 then
- timeRemaining = ((data.CoreStat.MaxRF-data.CoreStat.RF)/texts.RF.IOM)/20
- else
- timeRemaining = ""
- end
- return format(data.CoreStat.RF,"RF").."/"..format(data.CoreStat.MaxRF,"RF")..
- " ("..string.format("%0.2f",100*data.CoreStat.RF/data.CoreStat.MaxRF).."%) "..
- format(texts.RF.IOM,"RF",true).."/t "..format(timeRemaining,"time")..
- " "..activityIndicator[cycles%#activityIndicator+1]
- end,
- color = 0xffff00ff
- }
- }
- for i, v in pairs(rectangles) do
- v.object = canvas.addRectangle(0,0,0,0,0)
- end
- for i, v in pairs(texts) do
- v.object = canvas.addText({0,0},"",0)
- end
- while true do
- cycles = cycles+1
- getData()
- for i, v in pairs(rectangles) do
- local scalar, color
- if type(v.scalar) == "function" then
- scalar = v.scalar()
- else
- scalar = v.scalar
- end
- if type(v.color) == "function" then
- color = v.color()
- else
- color = v.color
- end
- v.object.setSize(v.size[1]*scalar[1]*scale, v.size[2]*scalar[2]*scale)
- v.object.setPosition((v.pos[1]+pos[1])*scale, (v.pos[2]+pos[2])*scale)
- v.object.setColor(color)
- end
- for i, v in pairs(texts) do
- local text
- if type(v.text) == "function" then
- text = v.text()
- else
- text = v.text
- end
- if type(v.color) == "function" then
- color = v.color()
- else
- color = v.color
- end
- v.object.setScale(scale*v.scale)
- v.object.setPosition((v.pos[1]+pos[1])*scale, (v.pos[2]+pos[2])*scale)
- v.object.setColor(color)
- v.object.setText(text)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment