const PI = 3.14159265359;
let rotationX = PI / 4, rotationY = PI / 4;
let prevMouseX, prevMouseY;
createCanvas(800, 800, WEBGL);
cols = floor(width / cellSize);
rows = floor(height / cellSize);
baseColor = color(random(100, 255), random(100, 255), random(100, 255));
for (let j = 0; j < rows; j++) {
for (let i = 0; i < cols; i++) {
grid.push(new Cell(i, j));
translate(-width / 2, -height / 2, 0);
let next = current.checkNeighbors();
removeWalls(current, next);
} else if (stack.length > 0) {
this.walls = [true, true, true, true];
this.color = lerpColor(baseColor, color(0), random(0.3, 0.7));
let x = this.i * cellSize;
let y = this.j * cellSize;
if (this.walls[0]) line(x, y, x + cellSize, y);
if (this.walls[1]) line(x + cellSize, y, x + cellSize, y + cellSize);
if (this.walls[2]) line(x + cellSize, y + cellSize, x, y + cellSize);
if (this.walls[3]) line(x, y + cellSize, x, y);
translate(x + cellSize / 2, y + cellSize / 2, -cellSize / 2);
box(cellSize - 2, cellSize - 2, cellSize - 2);
let top = grid[index(this.i, this.j - 1)];
let right = grid[index(this.i + 1, this.j)];
let bottom = grid[index(this.i, this.j + 1)];
let left = grid[index(this.i - 1, this.j)];
if (top && !top.visited) neighbors.push(top);
if (right && !right.visited) neighbors.push(right);
if (bottom && !bottom.visited) neighbors.push(bottom);
if (left && !left.visited) neighbors.push(left);
if (neighbors.length > 0) {
let r = floor(random(0, neighbors.length));
if (i < 0 || j < 0 || i >= cols || j >= rows) {
function removeWalls(a, b) {
function mouseDragged() {
rotationY += (mouseX - pmouseX) * sensitivity;
rotationX -= (mouseY - pmouseY) * sensitivity;