Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- initialize canvas
- local function createCanvas(imageWidth, imageHeight)
- canvas = {width = imageWidth, height = imageHeight, blitStrings = "", blitFrontColors = "", image = {}}
- -- populate unused blit strings for optimization
- for x=1,imageWidth do
- canvas.blitStrings = canvas.blitStrings.." "
- canvas.blitFrontColors = canvas.blitFrontColors.."0"
- end
- -- clear color initialize
- for x=1,imageWidth do
- imageColumn = {}
- for y=1,imageHeight do
- imageColumn[y] = 0
- end
- canvas.image[x] = imageColumn
- end
- return canvas
- end
- local function clearCanvas(canvas, color)
- for x=1,canvas.width do
- for y=1,canvas.height do
- canvas.image[x][y] = color
- end
- end
- end
- local function drawDotCanvas(canvas, xPos, yPos, color)
- if xPos < 1 or xPos > canvas.width or yPos < 1 or yPos > canvas.height then
- return
- end
- canvas.image[xPos][yPos] = color
- end
- local function drawBoxCanvas(canvas, xPos, yPos, width, height, color)
- for x=xPos,xPos+width do
- drawDotCanvas(canvas, x, yPos, color)
- end
- for y=yPos+1,yPos+height-1 do
- drawDotCanvas(canvas, xPos, y, color)
- drawDotCanvas(canvas, xPos+width, y, color)
- end
- for x=xPos,xPos+width do
- drawDotCanvas(canvas, x, yPos+height, color)
- end
- end
- local function drawBoxFilledCanvas(canvas, xPos, yPos, width, height, color)
- for x=xPos,xPos+width do
- for y=yPos,yPos+height do
- drawDotCanvas(canvas, x, y, color)
- end
- end
- end
- local function drawLineCanvas(canvas, xStartingPos, yStartingPos, xEndPos, yEndPos, color)
- dx = xEndPos - xStartingPos
- dy = yEndPos - yStartingPos
- x = xStartingPos
- y = yStartingPos
- decisionFactor = 2 * dy - dx
- while x < xEndPos do
- drawDotCanvas(canvas, x, y, color)
- if decisionFactor >= 0 then
- y = y + 1
- decisionFactor = decisionFactor + 2 * dy - 2 * dx
- else
- decisionFactor = decisionFactor + 2 * dy
- end
- x = x + 1
- end
- end
- local function _drawCirclePartCanvas(canvas, xPos, yPos, xOffset, yOffset, color)
- drawDotCanvas(canvas, xPos+xOffset, yPos+yOffset, color)
- drawDotCanvas(canvas, xPos-xOffset, yPos+yOffset, color)
- drawDotCanvas(canvas, xPos+xOffset, yPos-yOffset, color)
- drawDotCanvas(canvas, xPos-xOffset, yPos-yOffset, color)
- drawDotCanvas(canvas, xPos+yOffset, yPos+xOffset, color)
- drawDotCanvas(canvas, xPos-yOffset, yPos+xOffset, color)
- drawDotCanvas(canvas, xPos+yOffset, yPos-xOffset, color)
- drawDotCanvas(canvas, xPos-yOffset, yPos-xOffset, color)
- end
- local function drawCircleCanvas(canvas, xPos, yPos, radius, color)
- xOffset = 0
- yOffset = radius
- decisionFactor = 3 - (2 * radius)
- _drawCirclePartCanvas(canvas, xPos, yPos, xOffset, yOffset, color)
- while yOffset >= xOffset do
- xOffset = xOffset + 1
- if decisionFactor > 0 then
- yOffset = yOffset - 1
- decisionFactor = decisionFactor + 4 * (xOffset - yOffset) + 10
- else
- decisionFactor = decisionFactor + 4 * xOffset + 6
- end
- _drawCirclePartCanvas(canvas, xPos, yPos, xOffset, yOffset, color)
- end
- end
- local function blitCanvas(canvas, terminalRedirect)
- for y=1,canvas.height do
- blitBackColors = ""
- for x=1,canvas.width do
- blitBackColors = blitBackColors..colors.toBlit(canvas.image[x][y])
- end
- terminalRedirect.setCursorPos(1,y)
- terminalRedirect.blit(canvas.blitStrings, canvas.blitFrontColors, blitBackColors)
- end
- end
- offset = 0
- bottomMonitor = peripheral.wrap("top")
- topMonitor = peripheral.find("monitor")
- while true do
- timerID = os.startTimer(0.1)
- event, eventID = os.pullEvent("timer")
- topCanvas = createCanvas(29, 19)
- bottomCanvas = createCanvas(50, 33)
- clearCanvas(topCanvas, 2)
- clearCanvas(bottomCanvas, 4)
- drawCircleCanvas(topCanvas, 14, 9, 7, 2^((offset)%16))
- drawBoxCanvas(bottomCanvas, offset%bottomCanvas.width, offset%bottomCanvas.height, 4, 5, 2^((offset+1)%16))
- drawLineCanvas(bottomCanvas, 1, 1, 25, 6, 16)
- blitCanvas(topCanvas, topMonitor)
- blitCanvas(bottomCanvas, bottomMonitor)
- offset = offset + 1
- end
- --[[monitor = peripheral.wrap("top")
- monitor2 = peripheral.find("monitor")
- modem = peripheral.find("modem")
- offset = 0
- while true do
- timerID = os.startTimer(0.1)
- event, eventID = os.pullEvent("timer")
- for y=1,33 do
- spaces = ""
- frontColors = ""
- backColors = ""
- for x=1,50 do
- spaces = spaces.." "
- frontColors = frontColors.."0"
- if redstone.getInput("front") and x >= 20 and x <= 31 and y >= 6 and y <= 14 then
- backColors = backColors.."4"
- elseif redstone.getInput("back") and x >= 20 and x <= 31 and y >= 20 and y <= 28 then
- backColors = backColors.."4"
- elseif redstone.getInput("right") and x >= 9 and x <= 20 and y >= 13 and y <= 21 then
- backColors = backColors.."4"
- elseif redstone.getInput("left") and x >= 31 and x <= 42 and y >= 13 and y <= 21 then
- backColors = backColors.."4"
- else
- backColors = backColors..colors.toBlit(2^((offset+x+y)%16))
- end
- end
- monitor.setCursorPos(1,y)
- monitor.blit(spaces, frontColors, backColors)
- monitor2.setCursorPos(1,y)
- monitor2.blit(spaces, frontColors, backColors)
- --modem.callRemote("monitor_0","setCursorPos", 1, y)
- --modem.callRemote("monitor_0","blit", spaces, frontColors, backColors)
- end
- offset = offset + 1
- end--]]
Add Comment
Please, Sign In to add comment