Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.find("monitor")
- local matrix = peripheral.find("Induction Matrix")
- monitor.setTextScale(1)
- --print("Start in 3")
- --sleep(3)
- local w,h = monitor.getSize()
- local energywidth = w/3
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- function printEnergyBar()
- local energystart = w-1-energywidth
- local startbgcolor = monitor.getBackgroundColor()
- local startfgcolor = monitor.getTextColor()
- local level = matrix.getEnergy()/matrix.getMaxEnergy()
- local fieldheight = h-2
- local energylinefrom = fieldheight-fieldheight*level
- for i=2,h-1 do
- monitor.setCursorPos(energystart,i)
- for j=0,energywidth do
- if i >= energylinefrom then
- monitor.setBackgroundColor(colors.lime)
- else
- monitor.setBackgroundColor(colors.gray)
- end
- monitor.write(" ")
- end
- end
- monitor.setBackgroundColor(startbgcolor)
- monitor.setTextColor(startfgcolor)
- end
- local suffixes = {"","k","M","G","T"}
- function formatNumber(num)
- local idx = 1
- local prefix = ""
- if num < 0 then
- num = -num
- prefix = "-"
- end
- while num > 1000 do
- num = num/1000
- idx = idx+1
- end
- if idx > 1 then
- num = math.ceil(num*100)/100
- else
- num = math.ceil(num)
- end
- if not string.match(num,"%d+%.%d%d+") then
- if string.match(num,"%d+%.%d") then
- num = num.."0"
- elseif string.match(num,"%d+") then
- num = num..".00"
- end
- end
- return prefix..num..suffixes[idx]
- end
- function jToRF(joule)
- return joule/2.5
- end
- function printStats()
- local energyLine = 1/5*h
- local outputLine = 2/5*h
- local inputLine = 3/5*h
- local diffLine = 4/5*h
- local startbgcolor = monitor.getBackgroundColor()
- local startfgcolor = monitor.getTextColor()
- local energypercent = math.ceil(100*matrix.getEnergy()/matrix.getMaxEnergy())
- local outputPercent = math.ceil(100*matrix.getOutput()/matrix.getTransferCap())
- local inputPercent = math.ceil(100*matrix.getInput()/matrix.getTransferCap())
- local diff = jToRF(matrix.getInput()-matrix.getOutput())
- monitor.setCursorPos(2,energyLine)
- monitor.setTextColor(colors.lightGray)
- monitor.write(formatNumber(jToRF(matrix.getEnergy())).."RF ("..energypercent .."%)")
- monitor.setCursorPos(2,outputLine)
- monitor.setTextColor(colors.red)
- monitor.write("-"..formatNumber(jToRF(matrix.getOutput())).."RF/t ("..outputPercent .."%)")
- monitor.setCursorPos(2,inputLine)
- monitor.setTextColor(colors.green)
- monitor.write("+"..formatNumber(jToRF(matrix.getInput())).."RF/t ("..inputPercent .."%)")
- monitor.setCursorPos(2,diffLine)
- local prefix = ""
- if diff > 0 then
- monitor.setTextColor(colors.green)
- prefix = "+"
- elseif diff < 0.09 or diff > -0.09 then
- monitor.setTextColor(colors.gray)
- prefix = "±"
- diff = 0;
- else
- monitor.setTextColor(colors.red)
- end
- monitor.write(prefix..formatNumber(diff).."RF/t")
- monitor.setBackgroundColor(startbgcolor)
- monitor.setTextColor(startfgcolor)
- end
- while true do
- if type(matrix.getEnergy()) == "number" then
- monitor.clear()
- printEnergyBar()
- printStats()
- sleep(0.1)
- else
- sleep(1)
- end
- end
Add Comment
Please, Sign In to add comment