bobmarley12345

cc_os

Aug 25th, 2021 (edited)
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.97 KB | None | 0 0
  1. monitor_left = peripheral.wrap("monitor_44")
  2. monitor_middle = peripheral.wrap("monitor_45")
  3. monitor_right = peripheral.wrap("monitor_46")
  4.  
  5. Active_Monitor = nil
  6.  
  7. function calculateCenter(w, text)
  8.     return math.floor((w - string.len(text)) / 2) + 1
  9. end
  10.  
  11. function writeMonitor(x, y, text)
  12.     Active_Monitor.setCursorPos(x, y)
  13.     Active_Monitor.write(text)
  14. end
  15.  
  16. function clearBackground(colourr, textColour)
  17.     Active_Monitor.setBackgroundColor(colourr)
  18.     Active_Monitor.setTextColor(textColour)
  19.     Active_Monitor.clear()
  20. end
  21.  
  22. function ClearMonitor()
  23.     Active_Monitor.setTextColor(colours.black)
  24.     Active_Monitor.setBackgroundColor(colours.black)
  25.     Active_Monitor.clear()
  26.     Active_Monitor.setCursorPos(1,1)
  27. end
  28.  
  29. function DrawText(xPos, yPos, text, textColour, backgroundColour)
  30.     Active_Monitor.setBackgroundColor(backgroundColour)
  31.     Active_Monitor.setTextColor(textColour)
  32.     Active_Monitor.setCursorPos(xPos,yPos)
  33.     Active_Monitor.write(text)
  34. end
  35.  
  36. function DrawCenteredHorizontal(xPos, yPos, width, text, textColour, backgroundColour)
  37.     -- width could be the size of your monitor, or anything else. this means it
  38.     -- doesn't have to stretch your entire monitor's if you want. imagine
  39.     -- it as a rectangle and the text is in the center.
  40.     local textLength = string.len(text)
  41.     local centerX = (width / 2) - (textLength / 2)
  42.     DrawText(xPos + centerX, yPos, text, textColour, backgroundColour)
  43. end
  44.  
  45. function DrawLineH(xPos, yPos, lineLength, colour)
  46.     Active_Monitor.setBackgroundColor(colour)
  47.     Active_Monitor.setTextColor(colour)
  48.     Active_Monitor.setCursorPos(xPos,yPos)
  49.     Active_Monitor.write(string.rep(" ", lineLength))
  50. end
  51.  
  52. function DrawLineV(xPos, yPos, width, lineHeight, colour)
  53.     Active_Monitor.setBackgroundColor(colour)
  54.     for i = 1, lineHeight, 1 do
  55.         Active_Monitor.setCursorPos(xPos, yPos + (i - 1))
  56.         Active_Monitor.write(string.rep(" ", width))
  57.     end
  58. end
  59.  
  60. function DrawSquare(xPos, yPos, nWidth, nHeight, backgroundColour)
  61.     Active_Monitor.setBackgroundColor(backgroundColour)
  62.     for i = 1, math.ceil(nHeight), 1 do
  63.         Active_Monitor.setCursorPos(xPos, yPos + (i - 1))
  64.         Active_Monitor.write(string.rep(" ", nWidth))
  65.     end
  66. end
  67.  
  68. function ProgressBar(xPos, yPos, width, value, maxValue, backgroundColour, progressColour)
  69.     DrawLineH(xPos, yPos, width, backgroundColour) --backgoround bar
  70.     local barSize = math.floor((value/maxValue) * width)
  71.     DrawLineH(xPos, yPos, barSize, progressColour) --progress so far
  72. end
  73.  
  74. WINDOW_TITLE_COLOUR = colours.lightGrey
  75. WINDOW_CLIENT_COLOUR = colours.grey
  76.  
  77. progress_val = 20
  78.  
  79. function DrawWindow(title, x, y, w, h)
  80.     DrawSquare(x, y, w, 1, WINDOW_TITLE_COLOUR)
  81.     DrawText(x, y, title, colours.black, WINDOW_TITLE_COLOUR)
  82.     DrawSquare(x, y + 1, w, h - 1, WINDOW_CLIENT_COLOUR)
  83.     local buttonStart = x + w - 4
  84.     DrawText(buttonStart, y, "-", colours.white, colours.blue)
  85.     DrawText(buttonStart + 1, y, "[]", colours.white, colours.blue)
  86.     DrawText(buttonStart + 3, y, "x", colours.red, colours.blue)
  87. end
  88.  
  89. function drawLeftMonitor()
  90.     clearBackground(colours.white, colours.black)
  91.     DrawWindow("hello window xd", 2, 3, 20, 8)
  92.     DrawWindow("eek", 9, 12, 8, 5)
  93. end
  94.  
  95. function drawMiddleMonitor()
  96.     clearBackground(colours.white, colours.black)
  97.     DrawWindow("hello window xd", 7, 3, 24, 12)
  98.  
  99.     ProgressBar(8, 5, 22, progress_val, 100, colours.blue, colours.lightBlue)
  100. end
  101.  
  102. function drawRightMonitor()
  103.     clearBackground(colours.white, colours.black)
  104.     DrawWindow("xd", 3, 7, 10, 7)
  105. end
  106.  
  107. function main()
  108.     Active_Monitor = monitor_left
  109.     drawLeftMonitor()
  110.    
  111.     Active_Monitor = monitor_middle
  112.     drawMiddleMonitor()
  113.    
  114.     Active_Monitor = monitor_right
  115.     drawRightMonitor()
  116.    
  117.     Active_Monitor = nil
  118.  
  119.     progress_val = progress_val + 10
  120.     if (progress_val == 110) then
  121.         progress_val = 0
  122.     end
  123.  
  124.     os.sleep(0.5)
  125. end
  126.  
  127. while true do
  128.     main()
  129. end
Add Comment
Please, Sign In to add comment