let gridSize = 50; let cellSize; let path = []; function setup() { createCanvas(1000, 1000); cellSize = width/gridSize; background(255); stroke(0); strokeWeight(1); noFill(); let x = gridSize/2; let y = gridSize/2; let direction = "up"; let inputString = prompt("Enter the iterated Pisano cycle modulo n separated by commas"); let inputList = inputString.split(", ").map(Number); for (let i = 0; i < inputList.length; i++) { let num = inputList[i]; if (num == 0) { // stay still } else if (num % 2 == 0) { if (direction == "up") { direction = "left"; x--; } else if (direction == "down") { direction = "right"; x++; } else if (direction == "left") { direction = "down"; y++; } else if (direction == "right") { direction = "up"; y--; } } else { if (direction == "up") { direction = "right"; x++; } else if (direction == "down") { direction = "left"; x--; } else if (direction == "left") { direction = "up"; y--; } else if (direction == "right") { direction = "down"; y++; } } let xPos = (x+0.5)*cellSize; let yPos = (y+0.5)*cellSize; path.push({x: xPos, y: yPos}); } } function draw() { for (let i = 0; i < path.length-1; i++) { stroke(255, 0, 0); line(path[i].x, path[i].y, path[i+1].x, path[i+1].y); } }