Bumblebin

dd

Jan 21st, 2021 (edited)
802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.40 KB | None | 0 0
  1. -- initialize canvas
  2. local function createCanvas(imageWidth, imageHeight)
  3.   canvas = {width = imageWidth, height = imageHeight, blitStrings = "", blitFrontColors = "", image = {}}
  4.  
  5.   -- populate unused blit strings for optimization
  6.   for x=1,imageWidth do
  7.     canvas.blitStrings = canvas.blitStrings.." "
  8.     canvas.blitFrontColors = canvas.blitFrontColors.."0"
  9.   end
  10.  
  11.   -- clear color initialize
  12.   for x=1,imageWidth do
  13.     imageColumn = {}
  14.  
  15.     for y=1,imageHeight do
  16.       imageColumn[y] = 0
  17.     end
  18.  
  19.     canvas.image[x] = imageColumn
  20.   end
  21.  
  22.   return canvas
  23. end
  24.  
  25. local function clearCanvas(canvas, color)
  26.   for x=1,canvas.width do
  27.     for y=1,canvas.height do
  28.       canvas.image[x][y] = color
  29.     end
  30.   end
  31. end
  32.  
  33. local function drawDotCanvas(canvas, xPos, yPos, color)
  34.   if xPos < 1 or xPos > canvas.width or yPos < 1 or yPos > canvas.height then
  35.     return
  36.   end
  37.  
  38.   canvas.image[xPos][yPos] = color
  39. end
  40.  
  41. local function drawBoxCanvas(canvas, xPos, yPos, width, height, color)
  42.   for x=xPos,xPos+width do
  43.     drawDotCanvas(canvas, x, yPos, color)
  44.   end
  45.  
  46.   for y=yPos+1,yPos+height-1 do
  47.     drawDotCanvas(canvas, xPos, y, color)
  48.     drawDotCanvas(canvas, xPos+width, y, color)
  49.   end
  50.  
  51.   for x=xPos,xPos+width do
  52.     drawDotCanvas(canvas, x, yPos+height, color)
  53.   end
  54. end
  55.  
  56. local function drawBoxFilledCanvas(canvas, xPos, yPos, width, height, color)
  57.   for x=xPos,xPos+width do
  58.     for y=yPos,yPos+height do
  59.       drawDotCanvas(canvas, x, y, color)
  60.     end
  61.   end
  62. end
  63.  
  64. local function drawLineCanvas(canvas, xStartingPos, yStartingPos, xEndPos, yEndPos, color)
  65.   dx = xEndPos - xStartingPos
  66.   dy = yEndPos - yStartingPos
  67.   x = xStartingPos
  68.   y = yStartingPos
  69.   decisionFactor = 2 * dy - dx
  70.  
  71.   while x < xEndPos do
  72.     drawDotCanvas(canvas, x, y, color)
  73.     if decisionFactor >= 0 then
  74.       y = y + 1
  75.       decisionFactor = decisionFactor + 2 * dy - 2 * dx
  76.     else
  77.       decisionFactor = decisionFactor + 2 * dy
  78.     end
  79.     x = x + 1
  80.   end
  81. end
  82.  
  83. local function _drawCirclePartCanvas(canvas, xPos, yPos, xOffset, yOffset, color)
  84.   drawDotCanvas(canvas, xPos+xOffset, yPos+yOffset, color)
  85.   drawDotCanvas(canvas, xPos-xOffset, yPos+yOffset, color)
  86.   drawDotCanvas(canvas, xPos+xOffset, yPos-yOffset, color)
  87.   drawDotCanvas(canvas, xPos-xOffset, yPos-yOffset, color)
  88.   drawDotCanvas(canvas, xPos+yOffset, yPos+xOffset, color)
  89.   drawDotCanvas(canvas, xPos-yOffset, yPos+xOffset, color)
  90.   drawDotCanvas(canvas, xPos+yOffset, yPos-xOffset, color)
  91.   drawDotCanvas(canvas, xPos-yOffset, yPos-xOffset, color)
  92. end
  93.  
  94. local function drawCircleCanvas(canvas, xPos, yPos, radius, color)
  95.   xOffset = 0
  96.   yOffset = radius
  97.   decisionFactor = 3 - (2 * radius)
  98.  
  99.   _drawCirclePartCanvas(canvas, xPos, yPos, xOffset, yOffset, color)
  100.  
  101.   while yOffset >= xOffset do
  102.     xOffset = xOffset + 1
  103.     if decisionFactor > 0 then
  104.       yOffset = yOffset - 1
  105.       decisionFactor = decisionFactor + 4 * (xOffset - yOffset) + 10
  106.     else
  107.       decisionFactor = decisionFactor + 4 * xOffset + 6
  108.     end
  109.     _drawCirclePartCanvas(canvas, xPos, yPos, xOffset, yOffset, color)
  110.   end
  111. end
  112.  
  113. local function blitCanvas(canvas, terminalRedirect)
  114.   for y=1,canvas.height do
  115.     blitBackColors = ""
  116.     for x=1,canvas.width do
  117.       blitBackColors = blitBackColors..colors.toBlit(canvas.image[x][y])
  118.     end
  119.  
  120.     terminalRedirect.setCursorPos(1,y)
  121.     terminalRedirect.blit(canvas.blitStrings, canvas.blitFrontColors, blitBackColors)
  122.   end
  123. end
  124.  
  125.  
  126. offset = 0
  127. bottomMonitor = peripheral.wrap("top")
  128. topMonitor = peripheral.find("monitor")
  129.  
  130. while true do
  131.   timerID = os.startTimer(0.1)
  132.   event, eventID = os.pullEvent("timer")
  133.  
  134.   topCanvas = createCanvas(29, 19)
  135.   bottomCanvas = createCanvas(50, 33)
  136.  
  137.   clearCanvas(topCanvas, 2)
  138.   clearCanvas(bottomCanvas, 4)
  139.  
  140.   drawCircleCanvas(topCanvas, 14, 9, 7, 2^((offset)%16))
  141.   drawBoxCanvas(bottomCanvas, offset%bottomCanvas.width, offset%bottomCanvas.height, 4, 5, 2^((offset+1)%16))
  142.   drawLineCanvas(bottomCanvas, 1, 1, 25, 6, 16)
  143.  
  144.   blitCanvas(topCanvas, topMonitor)
  145.   blitCanvas(bottomCanvas, bottomMonitor)
  146.  
  147.   offset = offset + 1
  148. end
  149.  
  150.  
  151. --[[monitor = peripheral.wrap("top")
  152. monitor2 = peripheral.find("monitor")
  153. modem = peripheral.find("modem")
  154. offset = 0
  155.  
  156. while true do
  157.   timerID = os.startTimer(0.1)
  158.   event, eventID = os.pullEvent("timer")
  159.  
  160.   for y=1,33 do
  161.     spaces = ""
  162.     frontColors = ""
  163.     backColors = ""
  164.  
  165.     for x=1,50 do
  166.       spaces = spaces.." "
  167.       frontColors = frontColors.."0"
  168.  
  169.       if redstone.getInput("front") and x >= 20 and x <= 31 and y >= 6 and y <= 14 then
  170.         backColors = backColors.."4"
  171.       elseif redstone.getInput("back") and x >= 20 and x <= 31 and y >= 20 and y <= 28 then
  172.         backColors = backColors.."4"
  173.       elseif redstone.getInput("right") and x >= 9 and x <= 20 and y >= 13 and y <= 21 then
  174.         backColors = backColors.."4"
  175.       elseif redstone.getInput("left") and x >= 31 and x <= 42 and y >= 13 and y <= 21 then
  176.         backColors = backColors.."4"
  177.       else
  178.         backColors = backColors..colors.toBlit(2^((offset+x+y)%16))
  179.       end
  180.     end
  181.  
  182.     monitor.setCursorPos(1,y)
  183.     monitor.blit(spaces, frontColors, backColors)
  184.  
  185.     monitor2.setCursorPos(1,y)
  186.     monitor2.blit(spaces, frontColors, backColors)
  187.  
  188.     --modem.callRemote("monitor_0","setCursorPos", 1, y)
  189.     --modem.callRemote("monitor_0","blit", spaces, frontColors, backColors)
  190.   end
  191.  
  192.   offset = offset + 1
  193. end--]]
  194.  
Add Comment
Please, Sign In to add comment