bobmarley12345

nuclearreactorControlRoom

Oct 15th, 2020 (edited)
1,520
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- by ther xd
  2. -- Monitor is required, but you could set it to term
  3. -- if you want it to draw stuff to the terminal screen
  4. -- so... Monitor = term
  5. MonitorSide = "left"
  6. Monitor = peripheral.wrap(MonitorSide)
  7.  
  8. function ClearMonitor()
  9.     Monitor.setTextColor(colours.black)
  10.     Monitor.setBackgroundColor(colours.black)
  11.     Monitor.clear()
  12.     Monitor.setCursorPos(1,1)
  13. end
  14.  
  15. function DrawText(xPos, yPos, text, textColour, backgroundColour)
  16.     Monitor.setBackgroundColor(backgroundColour)
  17.     Monitor.setTextColor(textColour)
  18.     Monitor.setCursorPos(xPos,yPos)
  19.     Monitor.write(text)
  20. end
  21.  
  22. function DrawCenteredHorizontal(yPos, width, text, textColour, backgroundColour)
  23.     local textLength = string.len(text)
  24.     local centerX = (width / 2) - (textLength / 2)
  25.     DrawText(centerX, yPos, text, textColour, backgroundColour)
  26. end
  27.  
  28. function DrawLineH(xPos, yPos, lineLength, colour)
  29.     Monitor.setBackgroundColor(colour)
  30.     Monitor.setTextColor(colour)
  31.     Monitor.setCursorPos(xPos,yPos)
  32.     Monitor.write(string.rep(" ", lineLength))
  33. end
  34.  
  35. function DrawLineV(xPos, yPos, width, lineHeight, colour)
  36.     Monitor.setBackgroundColor(colour)
  37.     for i = 1, lineHeight, 1 do
  38.         Monitor.setCursorPos(xPos, yPos + (i - 1))
  39.         Monitor.write(string.rep(" ", width))
  40.     end
  41. end
  42.  
  43. function DrawSquare(xPos, yPos, nWidth, nHeight, backgroundColour)
  44.     Monitor.setBackgroundColor(backgroundColour)
  45.     for i = 1, math.ceil(nHeight / 1.5), 1 do
  46.         Monitor.setCursorPos(xPos, yPos + (i - 1))
  47.         Monitor.write(string.rep(" ", nWidth))
  48.     end
  49. end
  50.  
  51. function ProgressBar(xPos, yPos, width, value, maxValue, backgroundColour, progressColour)
  52.     DrawLineH(xPos, yPos, width, backgroundColour) --backgoround bar
  53.     local barSize = math.floor((value/maxValue) * width)
  54.     DrawLineH(xPos, yPos, barSize, progressColour) --progress so far
  55. end
  56.  
  57. function GroupBoxHeader(xPos, yPos, width, header, textColour, backgroundColour)
  58.     local headerLength = string.len(header)
  59.     local repeatChars = width - 4 - headerLength
  60.  
  61.     if (repeatChars < 0) then
  62.         repeatChars = 0
  63.     end
  64.  
  65.     local head = "--- " .. header .. " " .. string.rep("-", repeatChars)
  66.     DrawText(xPos, yPos, head, textColour, backgroundColour)
  67. end
  68.  
  69. function GroupBoxFooter(xPos, yPos, width, textColour, backgroundColour)
  70.     if (width < 0) then
  71.         width = 0
  72.     end
  73.     local head = string.rep("-", width)
  74.     DrawText(xPos, yPos, head, textColour, backgroundColour)
  75. end
  76.  
  77. function GroupBox(xPos, yPos, width, height, header, textColour, headerBackgroundColour)
  78.     GroupBoxHeader(xPos, yPos, width, header, textColour, headerBackgroundColour)
  79.     GroupBoxFooter(xPos, yPos + height + 1, width, textColour, headerBackgroundColour)
  80. end
  81.  
  82. function Between(value, betweenthis, andthis)
  83.     if (value >= betweenthis) then
  84.         if (value <= andthis) then
  85.             return true
  86.         end
  87.     end
  88.  
  89.     return false
  90. end
  91.  
  92. function ColourFromTemp(tempK)
  93.     if (tempK <= 410) then return colours.blue end
  94.     if (tempK <= 550) then return colours.cyan end
  95.     if (tempK <= 720) then return colours.yellow end
  96.     if (tempK <= 850) then return colours.orange end
  97.     if (tempK <= 1000) then return colours.red end
  98.  
  99.     return colours.black
  100. end
  101.  
  102. T1 = 0
  103. T2 = 0
  104. T3 = 0
  105. T4 = 0
  106. T5 = 0
  107. T6 = 0
  108. T7 = 0
  109. T8 = 0
  110. T9 = 0
  111. T10 = 0
  112. T11 = 0
  113. T12 = 0
  114. T13 = 0
  115. T14 = 0
  116. T15 = 0
  117. T16 = 0
  118. T17 = 0
  119. T18 = 0
  120. T19 = 0
  121. T20 = 0
  122. T21 = 0
  123. T22 = 0
  124. T23 = 0
  125. T24 = 0
  126. T25 = 0
  127.  
  128. function DrawControlRods(xPos, yPos)
  129.     local startX = xPos + 2
  130.     local startY = yPos + 2
  131.     local sqrW = 4
  132.     local sqrH = 4
  133.  
  134.     -- top
  135.     DrawLineH(startX - 1, startY - 1, (sqrW * 7) + 2, colours.grey)
  136.     -- bottom
  137.     DrawLineH(startX - 1, startY + (sqrH * 7) - 1, (sqrW * 7) + 2, colours.grey)
  138.     -- left
  139.     DrawLineV(startX - 1, startY - 1, 1, (sqrH * 7), colours.grey)
  140.     -- right
  141.     DrawLineV(startX + (sqrW * 7), startY - 1, 1, (sqrH * 7), colours.grey)
  142.  
  143.     DrawSquare(startX + (sqrW * 0), startY + (sqrH * 0), sqrW, sqrH, ColourFromTemp(T1))
  144.     DrawSquare(startX + (sqrW * 2), startY + (sqrH * 0), sqrW, sqrH, ColourFromTemp(T2))
  145.     DrawSquare(startX + (sqrW * 4), startY + (sqrH * 0), sqrW, sqrH, ColourFromTemp(T3))
  146.     DrawSquare(startX + (sqrW * 6), startY + (sqrH * 0), sqrW, sqrH, ColourFromTemp(T4))
  147.  
  148.     DrawSquare(startX + (sqrW * 1), startY + (sqrH * 1), sqrW, sqrH, ColourFromTemp(T4))
  149.     DrawSquare(startX + (sqrW * 3), startY + (sqrH * 1), sqrW, sqrH, ColourFromTemp(T4))
  150.     DrawSquare(startX + (sqrW * 5), startY + (sqrH * 1), sqrW, sqrH, ColourFromTemp(T4))
  151.  
  152.     DrawSquare(startX + (sqrW * 0), startY + (sqrH * 2), sqrW, sqrH, ColourFromTemp(T1))
  153.     DrawSquare(startX + (sqrW * 2), startY + (sqrH * 2), sqrW, sqrH, ColourFromTemp(T2))
  154.     DrawSquare(startX + (sqrW * 4), startY + (sqrH * 2), sqrW, sqrH, ColourFromTemp(T3))
  155.     DrawSquare(startX + (sqrW * 6), startY + (sqrH * 2), sqrW, sqrH, ColourFromTemp(T4))
  156.  
  157.     DrawSquare(startX + (sqrW * 1), startY + (sqrH * 3), sqrW, sqrH, ColourFromTemp(T4))
  158.     DrawSquare(startX + (sqrW * 3), startY + (sqrH * 3), sqrW, sqrH, ColourFromTemp(T4))
  159.     DrawSquare(startX + (sqrW * 5), startY + (sqrH * 3), sqrW, sqrH, ColourFromTemp(T4))
  160.  
  161.     DrawSquare(startX + (sqrW * 0), startY + (sqrH * 4), sqrW, sqrH, ColourFromTemp(T1))
  162.     DrawSquare(startX + (sqrW * 2), startY + (sqrH * 4), sqrW, sqrH, ColourFromTemp(T2))
  163.     DrawSquare(startX + (sqrW * 4), startY + (sqrH * 4), sqrW, sqrH, ColourFromTemp(T3))
  164.     DrawSquare(startX + (sqrW * 6), startY + (sqrH * 4), sqrW, sqrH, ColourFromTemp(T4))
  165.  
  166.     DrawSquare(startX + (sqrW * 1), startY + (sqrH * 5), sqrW, sqrH, ColourFromTemp(T4))
  167.     DrawSquare(startX + (sqrW * 3), startY + (sqrH * 5), sqrW, sqrH, ColourFromTemp(T4))
  168.     DrawSquare(startX + (sqrW * 5), startY + (sqrH * 5), sqrW, sqrH, ColourFromTemp(T4))
  169.  
  170.     DrawSquare(startX + (sqrW * 0), startY + (sqrH * 6), sqrW, sqrH, ColourFromTemp(T1))
  171.     DrawSquare(startX + (sqrW * 2), startY + (sqrH * 6), sqrW, sqrH, ColourFromTemp(T2))
  172.     DrawSquare(startX + (sqrW * 4), startY + (sqrH * 6), sqrW, sqrH, ColourFromTemp(T3))
  173.     DrawSquare(startX + (sqrW * 6), startY + (sqrH * 6), sqrW, sqrH, ColourFromTemp(T4))
  174. end
  175.  
  176. function Main()
  177.     while true do
  178.  
  179.         -- width = 82
  180.         -- height = 40
  181.  
  182.         -- start X = 37
  183.         -- start Y = 16
  184.  
  185.         ClearMonitor()
  186.  
  187.         DrawText(3, 2, "Control Rods", colours.orange, colours.black)
  188.         DrawControlRods(2, 4)
  189.  
  190.         os.sleep(1)
  191.     end
  192. end
  193.  
  194. Main()
RAW Paste Data