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
- _G.data = {}
- local cycles = -1
- function getData()
- rednet.send(124, "", "MECoreStat")
- local _, MECoreStatP = rednet.receive("MECoreStat",1)
- if MECoreStatP then data.MECoreStat = MECoreStatP end
- rednet.send(123, "", "DRCoreStat")
- local _, DRCoreStatP = rednet.receive("DRCoreStat",1)
- if DRCoreStatP then data.DRCoreStat = DRCoreStatP end
- rednet.send(122, "", "ReactorStat")
- local _, ReactorStatP = rednet.receive("ReactorStat",1)
- if ReactorStatP then data.reactor = ReactorStatP end
- end
- function format(I,M,S)
- I = tonumber(I)
- 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.max(math.floor(math.log(I)/math.log(1000)),0)
- return sign..string.format("%0.3f",I/1000^log)..suffixes[log]
- elseif M == "time" then
- if I >= 315360000000 then
- return "A:Long:Time"
- elseif I < 1 then
- return "No: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 = {
- {
- scalar = {1,1},
- pos = {0,0},
- size = {352, 41},
- color = 0x999999bb
- },
- RF1 = {
- scalar = function()
- return {data.DRCoreStat.RF/data.DRCoreStat.MaxRF, 1}
- end,
- pos = {1,1},
- size = {350, 9},
- color = 0xff0000bb,
- },
- RF2 = {
- scalar = function()
- return {data.MECoreStat.RF/data.MECoreStat.MaxRF, 1}
- end,
- pos = {1,11},
- size = {350, 9},
- color = 0xff0000bb,
- },
- ReactorTemp = {
- scalar = function()
- return {data.reactor.temp/8000, 1}
- end,
- pos = {1,21},
- size = {350,9},
- color = 0xff8800bb
- },
- ReactorShield = {
- scalar = function()
- return {data.reactor.shield/data.reactor.maxShield, 1}
- end,
- pos = {1,31},
- size = {350,9},
- color = 0x00ffffbb
- },
- --[[
- ReactorFuel2 = {
- scalar = {1,1},
- pos = {1,41},
- size = {350,9},
- color = 0xffaa00bb
- },
- ReactorFuel1 = {
- scalar = function()
- return {data.reactor.fuel/data.reactor.maxFuel, 1}
- end,
- pos = {1,41},
- size = {350,9},
- color = 0x000000bb
- },]]
- }
- local texts
- texts = {
- RF1 = {
- scale = 1,
- pos = {2,2},
- IO = 0,
- IOM = 0,
- text = function()
- texts.RF1.IO = texts.RF1.IO*(1-adjustmentRate) + data.DRCoreStat.IO*adjustmentRate
- if cycles%adjustmentCycles == 0 then
- texts.RF1.IO = (texts.RF1.IO-texts.RF1.IOM*(1-adjustmentRate)^adjustmentCycles)/(1-(1-adjustmentRate)^adjustmentCycles)
- texts.RF1.IOM = texts.RF1.IO
- end
- local timeRemaining
- if texts.RF1.IO < 0 then
- timeRemaining = -(data.DRCoreStat.RF/texts.RF1.IOM)/20
- elseif texts.RF1.IO > 0 then
- timeRemaining = ((data.DRCoreStat.MaxRF-data.DRCoreStat.RF)/texts.RF1.IOM)/20
- else
- timeRemaining = ""
- end
- return format(data.DRCoreStat.RF,"RF").."/"..format(data.DRCoreStat.MaxRF,"RF")..
- " ("..string.format("%0.2f",100*data.DRCoreStat.RF/data.DRCoreStat.MaxRF).."%) "..
- format(texts.RF1.IOM,"RF",true).."/t "..format(timeRemaining,"time")..
- " "..activityIndicator[cycles%#activityIndicator+1]
- end,
- color = 0xffff00ff
- },
- RF2 = {
- scale = 1,
- pos = {2,12},
- IO = 0,
- IOM = 0,
- text = function()
- texts.RF2.IO = texts.RF2.IO*(1-adjustmentRate) + data.MECoreStat.IO*adjustmentRate
- if cycles%adjustmentCycles == 0 then
- texts.RF2.IO = (texts.RF2.IO-texts.RF2.IOM*(1-adjustmentRate)^adjustmentCycles)/(1-(1-adjustmentRate)^adjustmentCycles)
- texts.RF2.IOM = texts.RF2.IO
- end
- local timeRemaining
- if texts.RF2.IO < 0 then
- timeRemaining = -(data.MECoreStat.RF/texts.RF2.IOM)/20
- elseif texts.RF2.IO > 0 then
- timeRemaining = ((data.MECoreStat.MaxRF-data.MECoreStat.RF)/texts.RF2.IOM)/20
- else
- timeRemaining = ""
- end
- return format(data.MECoreStat.RF,"RF").."/"..format(data.MECoreStat.MaxRF,"RF")..
- " ("..string.format("%0.2f",100*data.MECoreStat.RF/data.MECoreStat.MaxRF).."%) "..
- format(texts.RF2.IOM,"RF",true).."/t "..format(timeRemaining,"time")..
- " "..activityIndicator[cycles%#activityIndicator+1]
- end,
- color = 0xffff00ff
- },
- ReactorTemp = {
- scale = 1,
- pos = {2,22},
- text = function()
- return "Temp: "..data.reactor.temp.."C"
- end,
- color = 0xffffffff
- },
- ReactorShield = {
- scale = 1,
- pos = {2,32},
- text = function()
- return "Field: "..string.format("%0.2f",100*data.reactor.shield/data.reactor.maxShield).."%"
- end,
- color = 0xffffffff
- },
- --[[
- ReactorFuel = {
- scale = 1,
- pos = {2,42},
- text = function()
- return "Chaos: "..string.format("%0.2f",100*data.reactor.fuel/data.reactor.maxFuel).."%"
- end,
- color = 0xffffffff
- }]]
- }
- 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