Guest User

reactor

a guest
Feb 16th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.01 KB | None | 0 0
  1. reactor = peripheral.wrap('back')
  2.  
  3. mon = peripheral.wrap('right')
  4.  
  5. monX, monY = mon.getSize()
  6.  
  7. progColors = {
  8.   background = colors.black,
  9.   text = colors.white,
  10.   value = colors.purple,
  11.   energy = colors.green,
  12.   fuel = colors.blue
  13. }
  14.  
  15.  
  16. function monClear()
  17.  
  18. mon.setBackgroundColor(colors.black)
  19. mon.clear()
  20. mon.setCursorPos(1,1)
  21.  
  22. end
  23.  
  24. function percent(minVal, maxVal)
  25.  
  26. return math.floor((minVal/maxVal)*100)
  27.  
  28. end
  29.  
  30.  
  31.  
  32. function monWrite(x, y, text, textColor, backgroundColor)
  33.  
  34. textColor = textColor
  35. backgroundColor = backgroundColor
  36. mon.setCursorPos(x,y)
  37. mon.setBackgroundColor(backgroundColor)
  38. mon.setTextColor(textColor)
  39. mon.write(text)
  40.  
  41. end
  42.  
  43. function monCenter(y, text, textColor, backgroundColor)
  44.  
  45. monWrite((monX/2)-(#text/2),y,text,textColor,backgroundColor)
  46.  
  47. end
  48.  
  49. function monProgress(x,y,percent,name,barColor,backgroundColor, length,size)
  50.  
  51. length = length or (monX/2)+(monX/3)
  52. size = size or 2
  53.  
  54. for i = 0,size-1 do
  55.   monWrite(x,y+i, string.rep(" ", length), backgroundColor,backgroundColor)
  56.   monWrite(x,y+i, string.rep(" ", ((percent/100)*length)), barColor, barColor)
  57. end
  58.  
  59. barText = name.." "..math.floor(percent).."%"
  60.  
  61. if ((percent/100)*length) > #barText + 1  then
  62.   monWrite(x+(((percent/100)*length)-#barText),y+(size/2), barText, progColors.text,barColor)
  63. else
  64.   monWrite(x+((length/2)-(#barText/2)),y+(size/2), barText, progColors.text,backgroundColor)
  65. end
  66. end
  67.  
  68. function energyStored()
  69.  
  70. return(reactor.getEnergyStored())
  71.  
  72. end
  73.  
  74. function maxFuel()
  75.  
  76. return(reactor.getFuelAmountMax())
  77.  
  78. end
  79.  
  80. function fuelLevel()
  81.  
  82. return(reactor.getFuelAmount())
  83.  
  84. end
  85.  
  86. function currTemp()
  87.  
  88. return(reactor.getTemperature())
  89.  
  90. end
  91.  
  92. function RFOutput()
  93.  
  94. return(reactor.getEnergyProducedLastTick())
  95.  
  96. end
  97.  
  98. function reactorStatus()
  99.  
  100. status = reactor.getActive()
  101.  
  102. if status == true then
  103. return("Active")
  104. end
  105. if status == false then
  106. return("Shutdown")
  107. end
  108.  
  109. end
  110.  
  111.  
  112.  
  113.  
  114. function mainScreen(energyPercent,fuelPercent,tempPercent)
  115.  
  116. energyPercent = energyPercent or 0
  117. fuelPercent = fuelPercent or 0
  118. tempPercent = tempPercent or 0
  119.  
  120.  
  121. monProgress(15,8, energyPercent, "Energy", progColors.energy, colors.gray, 35,3)
  122. monProgress(15,12, fuelPercent, "Fuel", progColors.fuel, colors.gray, 35, 3)
  123. monProgress(15,16, tempPercent, "Temperature", colors.red, colors.gray, 35,3)
  124.  
  125. end
  126.  
  127. while true do
  128. monClear()
  129. energy = percent(energyStored(),10000000)
  130. fuel = percent(fuelLevel(), maxFuel())
  131. temp = percent(currTemp(), 2000)
  132.  
  133.  
  134. monCenter(4, "Daelie's Reactor 1", colors.yellow, colors.black)
  135. monWrite(1,9, "Redstone Flux", colors.purple, colors.black)
  136. monWrite(1,13, "Yellorium", colors.purple,colors.black)
  137. monWrite(1,17, "Temp: "..currTemp(), colors.purple, colors.black)
  138. mainScreen(energy, fuel, temp)
  139. monWrite(1,21, "Control Rods: 9", colors.purple,colors.black)
  140. monWrite(1,22, "Output: ".. math.floor(RFOutput()).." RF/t", colors.purple, colors.black)
  141. monWrite(1,23, "Reactor Status: " ..tostring(reactorStatus()), colors.purple, colors.black)
  142.  
  143.  
  144.  
  145. sleep(0.8)
  146. end
Advertisement
Add Comment
Please, Sign In to add comment