xxxxxxxxxx
103
let cols, rows;
let pixelSize = 80;
const palette = ["0fa3b1","b5e2fa","f9f7f3","eddea4","f7a072"].map(c => "#"+c)
function setup() {
createCanvas(1600, 1600);
cols = width / pixelSize;
rows = height / pixelSize;
noLoop();
randomSeed(72 + 4);
noiseSeed(99);
}
function draw() {
background(255);
for (let i = 0; i < cols; i++) {
for (let j = 0; j < rows; j++) {
// Calculate noise value for color variation
let noiseVal = noise(i * 0.1, j * 0.1) * 255;
// Calculate noise values for position variation
let xOffset = map(noise(i * 0.01, j * 0.01), 0, 1, -5, 5);
let yOffset = map(noise(i * 0.01 + 1000, j * 0.01 + 1000), 0, 1, -5, 5);
// Draw pixel with noise-infused color and position
fill(noiseVal); //, 200, 150);
stroke(200);
rect(
i * pixelSize + xOffset,
j * pixelSize + yOffset,
pixelSize,
pixelSize
);
}
}
const grid = new Array(cols * rows);
let tentatives = 4000;
while (true) {
if (tentatives <= 0) break;
let sPos = { x: floor(random(cols)), y: floor(random(rows)) };
if (grid[sPos.y * cols + sPos.x]) {
tentatives--;
continue;
}
grid[sPos.y * cols + sPos.x] = true;
stroke(150, random(100, 250), 200);
stroke(random(palette));
strokeWeight(pixelSize / 3);
for (let x = 0; x < 1400; x++) {
//let lr = random([-1, 0, 1]);
//let ud = random([-1, 0, 1]);
let [lr, ud] = random([
[0, 1],
[1, 0],
// [0, -1],
[0, -1],
// [-1, -1],
// [1, 1],
// [1, -1],
// [-1, 1],
]);
if (lr == 0 && ud == 0) {
continue;
}
if (sPos.y + ud < 0 || sPos.y + ud > rows - 1) {
continue;
}
if (sPos.x + lr < 0 || sPos.x + lr > cols - 1) {
continue;
}
if (grid[(sPos.y + ud) * cols + sPos.x + lr]) {
continue;
}
let newPos = { x: sPos.x + lr, y: sPos.y + ud };
line(
sPos.x * pixelSize + pixelSize / 2,
sPos.y * pixelSize + pixelSize / 2,
newPos.x * pixelSize + pixelSize / 2,
newPos.y * pixelSize + pixelSize / 2
);
sPos = newPos;
grid[sPos.y * cols + sPos.x] = true;
}
}
}