Advertisement
Guest User

A.R.C.S.

a guest
Jul 26th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.30 KB | None | 0 0
  1. mon = peripheral.wrap("monitor_0")
  2. os.loadAPI("touchpoint")
  3. t = touchpoint.new("monitor_0")
  4. rea = peripheral.wrap("right")
  5. monX, monY = mon.getSize()
  6.  
  7. --Clear Function
  8. function clear()
  9.         mon.setBackgroundColor(colors.black)
  10.         mon.clear()
  11.         mon.setCursorPos(1,1)
  12. end
  13.  
  14. --Draw Line Function
  15. function drawLine(x,y, length, size, color_bar)
  16.         for yPos = y, y+size-1 do
  17.                 mon.setBackgroundColor(color_bar)
  18.                 mon.setCursorPos(x, yPos)
  19.                 mon.write(string.rep(" ", length))
  20.         end
  21. end
  22.  
  23. --Progress Bar Function
  24. function drawProg(x, y, length, size, minVal, maxVal, color_bar, color_bg)
  25.         drawLine(x, y, length, size, color_bg)
  26.         local barSize = math.floor((minVal/maxVal)*length)
  27.         drawLine(x, y, barSize, size, color_bar)
  28. end
  29.  
  30. --Function for Centering Titles
  31. function centerText(title, y, per, value, maxValue)
  32.         mon.setBackgroundColor(colors.black)
  33.         mon.setTextColor(colors.white)
  34.         local txtX, txtY = mon.getSize()
  35.         if per == true then
  36.                 mon.setCursorPos((txtX+string.len(title))/2-(string.len(title)), y)
  37.                 mon.write(title..':'..math.floor((value/maxValue)*100).."%")
  38.         else
  39.                 mon.setCursorPos((txtX+string.len(title))/2-(string.len(title)-1), y)
  40.                 mon.write(title)
  41.         end
  42. end
  43.  
  44.         --Control Rod 1
  45.         t:add("A-10", R11, 2, 9, 5, 9)
  46.         t:add("A-5", R12, 7, 9, 9, 9)
  47.         t:add("A-1", R13, 11, 9, 13, 9)
  48.         t:add("A+1", R14, 70, 9, 72, 9)
  49.         t:add("A+5", R15, 74, 9, 76, 9)
  50.         t:add("A+10", R16, 78, 9, 81, 9)
  51.         --Control Rod 2
  52.         t:add("B-10", R21, 2, 11, 5, 11)
  53.         t:add("B-5", R22, 7, 11, 9, 11)
  54.         t:add("B-1", R23, 11, 11, 13, 11)
  55.         t:add("B+1", R24, 70, 11, 72, 11)
  56.         t:add("B+5", R25, 74, 11, 76, 11)
  57.         t:add("B+10", R26, 78, 11, 81, 11)
  58.        
  59.         --Control Rod 3
  60.         t:add("C-10", R31, 2, 13, 5, 13)
  61.         t:add("C-5", R32, 7, 13, 9, 13)
  62.         t:add("C-1", R33, 11, 13, 13, 13)
  63.         t:add("C+1", R34, 70, 13, 72, 13)
  64.         t:add("C+5", R35, 74, 13, 76, 13)
  65.         t:add("C+10", R36, 78, 13, 81, 13)
  66.        
  67.         --Control Rod 4
  68.         t:add("D-10", R41, 2, 15, 5, 15)
  69.         t:add("D-5", R42, 7, 15, 9, 15)
  70.         t:add("D-1", R43, 11, 15, 13, 15)
  71.         t:add("D+1", R44, 70, 15, 72, 15)
  72.         t:add("D+5", R45, 74, 15, 76, 15)
  73.         t:add("D+10", R46, 78, 15, 81, 15)
  74.        
  75.         --Control Rod 5
  76.         t:add("E-10", R51, 2, 17, 5, 17)
  77.         t:add("E-5", R52, 7, 17, 9, 17)
  78.         t:add("E-1", R53, 11, 17, 13, 17)
  79.         t:add("E+1", R54, 70, 17, 72, 17)
  80.         t:add("E+5", R55, 74, 17, 76, 17)
  81.         t:add("E+10", R56, 78, 17, 81, 17)
  82.        
  83.         --Additional buttons
  84.         t:add("On/Off", OnOff, 1, 1, 6, 1)
  85.         t:add("X", stopProgram, 82, 1, 82, 1)
  86.  
  87. --Button Functions
  88.   --Control Rod 1
  89. function R11()
  90.         rea.setControlRodLevel(1, rea.getControlRodLevel(1)-10)
  91. end
  92. function R12()
  93.         rea.setControlRodLevel(1, rea.getControlRodLevel(1)-5)
  94. end
  95. function R13()
  96.         rea.setControlRodLevel(1, rea.getControlRodLevel(1)-1)
  97. end
  98. function R14()
  99.         rea.setControlRodLevel(1, rea.getControlRodLevel(1)+10)
  100. end
  101. function R15()
  102.         rea.setControlRodLevel(1, rea.getControlRodLevel(1)+5)
  103. end
  104. function R16()
  105.         rea.setControlRodLevel(1, rea.getControlRodLevel(1)+1)
  106. end
  107.   --Control Rod 2
  108. function R21()
  109.         rea.setControlRodLevel(2, rea.getControlRodLevel(2)-10)
  110. end
  111. function R22()
  112.         rea.setControlRodLevel(2, rea.getControlRodLevel(2)-5)
  113. end
  114. function R23()
  115.         rea.setControlRodLevel(2, rea.getControlRodLevel(2)-1)
  116. end
  117. function R24()
  118.         rea.setControlRodLevel(2, rea.getControlRodLevel(2)+1)
  119. end
  120. function R25()
  121.         rea.setControlRodLevel(2, rea.getControlRodLevel(2)+5)
  122. end
  123. function R26()
  124.         rea.setControlRodLevel(2, rea.getControlRodLevel(2)+10)
  125. end
  126.   --Control Rod 3
  127. function R31()
  128.         rea.setControlRodLevel(3, rea.getControlRodLevel(3)-10)
  129. end
  130. function R32()
  131.         rea.setControlRodLevel(3, rea.getControlRodLevel(3)-5)
  132. end
  133. function R33()
  134.         rea.setControlRodLevel(3, rea.getControlRodLevel(3)-1)
  135. end
  136. function R34()
  137.         rea.setControlRodLevel(3, rea.getControlRodLevel(3)+1)
  138. end
  139. function R35()
  140.         rea.setControlRodLevel(3, rea.getControlRodLevel(3)+5)
  141. end
  142. function R36()
  143.         rea.setControlRodLevel(3, rea.getControlRodLevel(3)+10)
  144. end
  145.   --Control Rod 4
  146. function R41()
  147.         rea.setControlRodLevel(4, rea.getControlRodLevel(4)-10)
  148. end
  149. function R42()
  150.         rea.setControlRodLevel(4, rea.getControlRodLevel(4)-5)
  151. end
  152. function R43()
  153.         rea.setControlRodLevel(4, rea.getControlRodLevel(4)-1)
  154. end
  155. function R44()
  156.         rea.setControlRodLevel(4, rea.getControlRodLevel(4)+1)
  157. end
  158. function R45()
  159.         rea.setControlRodLevel(4, rea.getControlRodLevel(4)+5)
  160. end
  161. function R46()
  162.         rea.setControlRodLevel(4, rea.getControlRodLevel(4)+10)
  163. end
  164.   --Control Rod 5
  165. function R51()
  166.         rea.setControlRodLevel(5, rea.getControlRodLevel(5)-10)
  167. end
  168. function R52()
  169.         rea.setControlRodLevel(5, rea.getControlRodLevel(5)-5)
  170. end
  171. function R53()
  172.         rea.setControlRodLevel(5, rea.getControlRodLevel(5)-1)
  173. end
  174. function R54()
  175.         rea.setControlRodLevel(5, rea.getControlRodLevel(5)+1)
  176. end
  177. function R55()
  178.         rea.setControlRodLevel(5, rea.getControlRodLevel(5)+5)
  179. end
  180. function R56()
  181.         rea.setControlRodLevel(5, rea.getControlRodLevel(5)+10)
  182. end
  183.   --Other buttons
  184. function OnOff()
  185.         if rea.getActive == true then
  186.                 rea.setActive(false)
  187.         else
  188.                 rea.setActive(true)
  189.         end
  190. end
  191.  
  192. function stopProgram()
  193.   SD = true
  194. end
  195.  
  196. --Progress bar updates and control rod control
  197. local SD = false
  198. while SD == false do
  199.   t:draw
  200.    
  201.   --Main Title
  202.     centerText("A.R.C.S.", 1, false, 0, 0)
  203.          
  204.   --Power Bar
  205.     centerText("energy Stored", 4, true, rea.getEnergyStored(), 10000000)
  206.     drawProg(14, 5, 54, 1, rea.getEnergyStored(), 10000000, colors.green, colors.red)
  207.          
  208.   --Stored Fuel
  209.     centerText('Fuel Stored', 6, true, rea.getFuelAmount(), rea.getFuelAmountMax())
  210.     drawProg(14, 7, 54, 1, rea.getFuelAmount(), rea.getFuelAmountMax(), colors.green, colors.red)
  211.          
  212.   --Control Rod 1
  213.     centerText('Control Rod 1 Insertion', 8, true, rea.getControlRodLevel(0), 100)
  214.     drawProg(14, 9, 54, 1, rea.getControlRodLevel(0), 100, colors.green, colors.red)
  215.          
  216.   --Control Rod 2
  217.     centerText('Control Rod 2 Insertion', 10, true, rea.getControlRodLevel(1), 100)
  218.     drawProg(14, 11, 54, 1, rea.getControlRodLevel(1), 100, colors.green, colors.red)
  219.          
  220.   --Control Rod 3
  221.     centerText('Control Rod 3 Insertion', 12, true, rea.getControlRodLevel(2), 100)
  222.     drawProg(14, 13, 54, 1, rea.getControlRodLevel(2), 100, colors.green, colors.red)
  223.          
  224.   --Control Rod 4
  225.     centerText('Control Rod 4 Insertion', 14, true, rea.getControlRodLevel(3), 100)
  226.     drawProg(14, 15, 54, 1, rea.getControlRodLevel(3), 100, colors.green, colors.red)
  227.      
  228.   --Control Rod 5
  229.     centerText('Control Rod 5 Insertion', 16, true, rea.getControlRodLevel(4), 100)
  230.     drawProg(14, 17, 54, 1, rea.getControlRodLevel(4), 100, colors.green, colors.red)
  231.          
  232.   --Other Things
  233.     sleep(0.1)
  234. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement