Last active
December 26, 2023 07:40
-
-
Save zeng-github01/5b6a4d8338350a6dfd4d2a1fee2c1e0a to your computer and use it in GitHub Desktop.
Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local component = require("component") | |
local computer = require("computer") | |
local gpu = component.gpu | |
local event = require("event") | |
local unicode = require("unicode") | |
local package = require("package") | |
local graphlib = require("graphlib") | |
local thread = require("thread") | |
local screenViewport = {gpu.getViewport()} | |
local w, h = gpu.getResolution() | |
local factor = (1156 / 949 + 4430 / 3635) / 2 | |
if not component.isAvailable("nc_fusion_reactor") then | |
local string = 'there is no reactor' | |
WIDTH , HEIGHT = screenViewport[1], screenViewport[2] | |
gpu.setViewport(WIDTH , HEIGHT) | |
gpu.fill(1, 1, WIDTH, HEIGHT, ' ') | |
gpu.set((WIDTH - #string) / 2 , HEIGHT / 2 , string) | |
os.sleep(5) | |
gpu.fill(1, 1, WIDTH, HEIGHT, ' ') | |
os.exit() | |
end | |
local reactor = component.getPrimary("nc_fusion_reactor") | |
reactor.optimumTemperature = reactor.getFusionComboHeatVariable() * factor | |
local temperature = {} | |
local battery = {} | |
local efficiency = {} | |
for i = 1, 35 do | |
temperature[i] = 0 | |
battery[i] = 0 | |
efficiency[i] = 0 | |
end | |
local function reactorLoop(reactor) | |
while true do | |
local tem = reactor.getTemperature() / 1e6 | |
if(tem > reactor.optimumTemperature * 1.001) then | |
reactor.deactivate() | |
os.sleep(1) | |
reactor.activate() | |
elseif(tem < reactor.optimumTemperature * 0.999) then | |
reactor.activate() | |
os.sleep(1) | |
else | |
os.sleep(1) | |
end | |
end | |
end | |
local reactorInterval = 1 | |
local updateTimes = 0 | |
local passTime = computer.uptime() | |
local passTimeLast = 0 | |
local function drawChart() | |
gpu.fill(1,1,w,h," ") | |
while true do | |
passTime = computer.uptime() | |
if passTime > passTimeLast + reactorInterval then | |
graphlib.cycleTable(temperature,math.floor(reactor.getTemperature() / 1e6)) | |
graphlib.cycleTable(battery,string.format("%.3f",reactor.getEnergyStored() / 1e3)) | |
graphlib.cycleTable(efficiency,math.floor(reactor.getEfficiency())) | |
passTimeLast = passTime | |
updateTimes = updateTimes + 1 | |
end | |
gpu.setForeground(0xFF6D00) | |
gpu.setBackground(0x1E1E1E) | |
graphlib.drawGraph(temperature, w-87-3, 3, 35, 16, reactor.getMaxTemperature() / 1e6, {legend=true,title="Temperature",textbg=0x0F0F0F,current=true}) | |
gpu.setForeground(0xFF0040) | |
graphlib.drawGraph(battery, w-35-3, 3, 35, 16, string.format("%.3f",reactor.getMaxEnergyStored() / 1e3) , {style=1,legend=true,title="Battery (kRF)",textbg=0x0F0F0F,current=true}) | |
gpu.setForeground(0x00FF80) | |
graphlib.drawGraph(efficiency, 5+12, 3, 35, 16, 100, {style=1,legend=true,title="Efficiency",textbg=0x0F0F0F,current=true}) | |
gpu.setForeground(0xFFFFFF) | |
gpu.setBackground(0x000000) | |
end | |
end | |
local threadReactor = thread.create(reactorLoop,reactor) | |
local threadChart = thread.create(drawChart) | |
gpu.fill(1,1,w,h," ") | |
os.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment