Advertisement
Nonsanity

OpenComputer Fusion Reactor Monitor Program mk1

Aug 22nd, 2015
1,586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.64 KB | None | 0 0
  1. local component = require( "component" )
  2. local gpu = component.gpu
  3. local power = component.mekanism_machine
  4. local event = require( "event" )
  5.  
  6.  
  7. local oldW, oldH = gpu.getResolution()
  8. gpu.setResolution( 80, 11 )
  9.  
  10.  
  11. function clearScreen()
  12.   local oldColor = gpu.getBackground( false )
  13.   local w,h = gpu.getResolution()
  14.   gpu.setBackground( 0x000000, false )
  15.   gpu.fill( 1, 1, w, h, " " )
  16.   gpu.setBackground( oldColor, false )
  17. end
  18.  
  19.  
  20. function progressBar( label, y, value, maxVal, color, show, unit )
  21.   local oldColor = gpu.getBackground( false )
  22.   gpu.setBackground(0x000000, false)
  23.   gpu.fill( 3, y, 75, 2, " " )
  24.   w = math.floor( value * (75 / maxVal) )
  25.   p = math.floor( (w / 75) * 100 )
  26.   gpu.set( 3, y, label .. ": " .. tostring( p ) .. "%" )
  27.   gpu.setBackground( 0x222222, false )
  28.   gpu.fill( 3, y+1, 75, 1, " " )
  29.   gpu.setBackground( color, false )
  30.   gpu.fill( 3, y+1, w, 1, " " )
  31.   gpu.setBackground( oldColor, false )
  32.   if show then
  33.     local valStr = formatBig( value ) .. unit
  34.     local n = string.len( valStr )
  35.     gpu.set( 78 - n, y, valStr )
  36.   end
  37. end
  38.  
  39.  
  40. function assignTanks()
  41.   local tanks = component.list( "comparator" )
  42.   local t1 = component.getPrimary( "comparator" )
  43.   local t2
  44.   for k,v in tanks do
  45.     local temp = component.proxy( k )
  46.     if t1.address ~= temp.address then t2 = temp end
  47.   end
  48.   return t1,t2
  49. end
  50.  
  51.  
  52. function formatBig( value )
  53.   local output = ""
  54.   local valRem = 0
  55.   local valPart = 0
  56.   while value > 0 do
  57.     valRem = math.floor( value / 1000 )
  58.     valPart = value - (valRem * 1000)
  59.     if output == "" then
  60.       output = string.format( "%03d", valPart )
  61.     elseif valRem == 0 then
  62.       output = valPart .. "," .. output
  63.     else
  64.       output = string.format( "%03d", valPart ) .. "," .. output
  65.     end
  66.     value = valRem
  67.   end
  68.   return output
  69. end
  70.  
  71.  
  72.  
  73.  
  74. local tank1, tank2 = assignTanks()
  75.  
  76. clearScreen()
  77. local max = math.floor( power.getMaxEnergyStored() * 0.4 )
  78. local cur = math.floor( power.getEnergyStored() * 0.4 )
  79. gpu.set( 28, 1, "Reactor  Fuel  Reserves" )
  80. gpu.set( 3, 10, "Power Output: 18,000,000 RF/sec" )
  81. local totalStr = formatBig( max ) .. " RF"
  82. gpu.set( 78 - string.len( totalStr ), 10, totalStr )
  83. while true do
  84.   local _,_,x,y = event.pull( 1, "touch" )
  85.   if x and y then goto quit end
  86.  
  87.   progressBar( "Deuterium", 2, tank2.getOutputSignal(), 15, 0xff0000, false, "" )
  88.   progressBar( "Tritium", 5, tank1.getOutputSignal(), 15, 0x0088ff, false, "" )
  89.  
  90.   cur = math.floor( power.getEnergyStored() * 0.4 )
  91.   progressBar( "Power Stored", 8, cur, max, 0x00bb00, true, " RF" )
  92.  
  93.   os.sleep(0.25)
  94. end
  95.  
  96.  
  97. ::quit::
  98. gpu.setResolution( oldW, oldH )
  99. clearScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement