bobmarley12345

PACoolDisplay

Oct 24th, 2020 (edited)
1,365
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MonitorSide = "left"
  2. Monitor = peripheral.wrap(MonitorSide)
  3.  
  4. function GetMonSize()
  5.     if ((Monitor == nil) == false) then
  6.         return Monitor.getSize()
  7.     else
  8.         return 0,0
  9.     end
  10. end
  11.  
  12. function DrawText(xPos, yPos, text, textColour, backgroundColour)
  13.     Monitor.setBackgroundColor(backgroundColour)
  14.     Monitor.setTextColor(textColour)
  15.     Monitor.setCursorPos(xPos,yPos)
  16.     Monitor.write(text)
  17. end
  18.  
  19. function DrawCenteredHorizontal(xPos, yPos, width, text, textColour, backgroundColour)
  20.     -- width could be the size of your monitor, or anything else. this means it
  21.     -- doesn't have to stretch your entire monitor's if you want. imagine
  22.     -- it as a rectangle and the text is in the center.
  23.     local textLength = string.len(text)
  24.     local centerX = (width / 2) - (textLength / 2)
  25.     DrawText(xPos + centerX, yPos, text, textColour, backgroundColour)
  26. end
  27.  
  28. function DrawSquare(xPos, yPos, nWidth, nHeight, backgroundColour)
  29.     Monitor.setBackgroundColor(backgroundColour)
  30.     Monitor.setTextColor(backgroundColour)
  31.     for i = 1, math.ceil(nHeight), 1 do
  32.         Monitor.setCursorPos(xPos, yPos + (i - 1))
  33.         Monitor.write(string.rep(" ", nWidth))
  34.     end
  35. end
  36.  
  37. ParticlePos = {}
  38. ParticleColour = colours.white
  39. ParticleColourBorder = colours.black
  40. ParticleSizeX = 5
  41. ParticleSizeY = 3
  42. ParticleSpeed = 1
  43.  
  44. Direction = { left = 1, up = 2, right = 3, down = 4}
  45. ParticleDirection = Direction.right
  46.  
  47. GeneratorStatusDirection = "bottom"
  48.  
  49. function IsGeneratorOn()
  50.     return redstone.getInput(GeneratorStatusDirection)    
  51. end
  52.  
  53. function Main()
  54.     local PAStartX = 4
  55.     local PAStartY = 4
  56.     ParticlePos.x = PAStartX
  57.     ParticlePos.y = PAStartY
  58.  
  59.     while true do
  60.         local w, h = GetMonSize()
  61.         local centerY = math.floor(h / 2) + 1
  62.         local PAWidth = w - PAStartX - 2
  63.         local PAHeight = h - PAStartY - 1
  64.         local PAEndX = PAWidth-- + math.floor(ParticleSizeX / 2)
  65.         local PAEndY = PAHeight + math.floor(ParticleSizeY / 2)
  66.        
  67.         if (ParticleDirection == Direction.right) then
  68.             ParticlePos.x = ParticlePos.x + ParticleSpeed
  69.         end
  70.  
  71.         if (ParticleDirection == Direction.down) then
  72.             ParticlePos.y = ParticlePos.y + ParticleSpeed
  73.         end
  74.  
  75.         if (ParticleDirection == Direction.left) then
  76.             ParticlePos.x = ParticlePos.x - ParticleSpeed
  77.         end
  78.  
  79.         if (ParticleDirection == Direction.up) then
  80.             ParticlePos.y = ParticlePos.y - ParticleSpeed
  81.         end
  82.  
  83.         if ((ParticleDirection ~= Direction.left) and (ParticlePos.x >= PAEndX)) then
  84.             ParticleDirection = Direction.down
  85.         end
  86.  
  87.         if ((ParticleDirection ~= Direction.up) and (ParticlePos.y >= PAEndY)) then
  88.             ParticleDirection = Direction.left
  89.         end
  90.  
  91.         if ((ParticleDirection == Direction.left) and (ParticlePos.x == PAStartX)) then
  92.             ParticleDirection = Direction.up
  93.         end
  94.  
  95.         if ((ParticleDirection == Direction.up) and ((ParticlePos.x == PAStartX) and (ParticlePos.y == PAStartY))) then
  96.             ParticleDirection = Direction.right
  97.         end
  98.  
  99.         local bgColour
  100.         local genOn
  101.  
  102.         if (IsGeneratorOn()) then
  103.             bgColour = colours.green
  104.             genOn = true
  105.         else
  106.             bgColour = colours.red
  107.             genOn = false
  108.         end
  109.  
  110.         Monitor.setBackgroundColor(bgColour)
  111.         Monitor.setTextColor(bgColour)
  112.         Monitor.clear()
  113.        
  114.         --DrawSquare(ParticlePos.x - 2, ParticlePos.y - 1, ParticleSizeX + 4, ParticleSizeY + 2, ParticleColourBorder)
  115.         DrawSquare(PAStartX + 2, PAStartY + 1, PAWidth - 3, PAHeight - 2, colours.orange)
  116.         DrawSquare(PAStartX + 3, PAStartY + 2, PAWidth - 5, PAHeight - 4, bgColour)
  117.         DrawSquare(ParticlePos.x, ParticlePos.y, ParticleSizeX, ParticleSizeY, ParticleColour)
  118.  
  119.         Monitor.setTextColor(colours.white)
  120.  
  121.         if (genOn) then
  122.             DrawCenteredHorizontal(1, centerY - 1, w, "Dark Matter Generator", colours.white, colours.green)
  123.             DrawCenteredHorizontal(1, centerY, w, "ONLINE", colours.white, colours.green)
  124.         else
  125.             DrawCenteredHorizontal(1, centerY - 1, w, "Dark Matter Generator", colours.white, colours.red)
  126.             DrawCenteredHorizontal(1, centerY, w, "OFFLINE", colours.white, colours.red)
  127.         end
  128.        
  129.         sleep(0.1)
  130.     end
  131. end
  132.  
  133. Main()
RAW Paste Data