xxxxxxxxxx
87
const RINGS = 10;
const WALL_SIZE = 5;
const DOOR_SIZE = 10;
const MIN_RAD = 20;
const MAX_RAD = 190;
const MIN_DIV_OUTER = 5;
const MAX_DIV_OUTER = 10;
const MIN_DIV_INNER = 1;
const MAX_DIV_INNER = 2;
function setup() {
createCanvas(400, 400);
noLoop();
}
function draw() {
clear();
drawMaze();
}
function drawMaze() {
push();
translate(width/2, height/2);
rectMode(CENTER);
strokeCap(SQUARE);
noFill();
stroke(255);
strokeWeight(WALL_SIZE);
const divisions = [];
for(let i = 0; i < RINGS; i ++) {
const rad = map(i, 0, RINGS, MAX_RAD, MIN_RAD);
circle(0, 0, rad * 2);
// How many divisions in this ring
const minDiv = map(i, 0, RINGS, MIN_DIV_OUTER, MIN_DIV_INNER);
const maxDiv = map(i, 0, RINGS, MAX_DIV_OUTER, MAX_DIV_INNER);
const divs = int(random(minDiv, maxDiv));
divisions.push(divs);
// Can't add divisions on outer most rings
if(i == 0) {
continue;
}
const prevRad = map(i - 1, 0, RINGS, MAX_RAD, MIN_RAD);
// Add room divisions
for(let d = 0; d < divs; d ++) {
const ang = random(TAU);
const x = cos(ang);
const y = sin(ang);
line(x * rad, y * rad, x * prevRad, y * prevRad);
}
}
// Add inter-ring connections
blendMode(REMOVE);
noStroke();
fill(255, 0, 0);
for(let i = 0; i < divisions.length; i ++) {
const rad = map(i, 0, RINGS, MAX_RAD, MIN_RAD);
const divs = divisions[i];
for(let c = 0; c < divs; c ++) {
const ang = random(TAU);
push();
rotate(ang);
rect(rad, 0, WALL_SIZE + 2, DOOR_SIZE);
pop();
}
}
blendMode(BLEND);
pop();
}