xxxxxxxxxx
74
let cellsize;
function drawCell(x, y, np, coff, off) {
let pts = [];
let xs = [];
let ys = [];
for (let _y = y+coff; _y < y+off; _y += coff) {
ys.push(_y)
}
for (let _x = x+coff; _x < x+off; _x += coff) {
xs.push(_x);
}
for (let i = 0; i < xs.length; i++) {
pts.push({x: xs[i], y: y, done: false});
pts.push({x: xs[i], y: y+off, done: false});
}
for (let i = 0; i < ys.length; i++) {
pts.push({x: x, y: ys[i], done: false});
pts.push({x: x+off, y: ys[i], done: false});
}
done = false;
while (!done) {
let plen = pts.filter((pt) => pt.done);
if (plen.length == pts.length) {
done = true;
break;
}
let pt1 = random(pts);
let pt2 = random(pts);
while (pt1 == pt2 || pt1.x == pt2.x || pt1.y == pt2.y) {
pt2 = random(pts);
}
pt1.done = true;
pt2.done = true;
line(pt1.x, pt1.y, pt2.x, pt2.y);
}
}
function setup() {
createCanvas(1800, 1800);
background(20);
stroke(color(220,220,220,80));
strokeWeight(1);
pixelDensity(1);
let off = width * 0.01;//1;
for (let y = off; y < height; y += off) {
line(0, y, width, y);
}
for (let x = off; x < width; x += off) {
line(x, 0, x, height);
}
stroke(220);
let npts = 2;
let coff = off / npts;
for (let y = off; y < height-off; y += off) {
for (let x = off; x < width-off; x += off) {
drawCell(x, y, npts, coff, off);
}
}
noFill();
strokeWeight(2);
rect(off, off, width-2*off, height-2*off);
// drawCell(off, off, npts, coff, off);
}
function draw() {
// background(220);
}