xxxxxxxxxx
139
let logo;
// P5Capture.setDefaultOptions({
// format: "png",
// quality: 1,
// width: 1080,
// });
function preload() {
logo = loadImage('logo-horizontal.png');
}
let noiseScale = 0.01;
let cols = 200;
let rows = 200;
let thresholdValues = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9];
let nz = 0;
let speed = 0.1;
function setup() {
createCanvas(600, 600);
// noLoop();
}
function createNoiseGrid(rows, cols) {
let noiseValues = [];
for (let y = 0; y < rows; y++) {
let row = [];
for (let x = 0; x < cols; x++) {
let nx = x * noiseScale;
let ny = y * noiseScale;
row.push(noise(nx, ny, nz));
}
noiseValues.push(row);
}
return noiseValues;
}
function draw() {
background("#dfb2b6");
noFill();
// noiseSeed(55);
noiseValues = createNoiseGrid(rows, cols);
let cellSize = width / cols;
nz += noiseScale * speed;
colorGenerator = new ColorGenerator('#96000e');
colors = colorGenerator.getTints(thresholdValues.length);
let i = 0;
for (let t of thresholdValues) {
stroke(colors[i]);
// Calculate the stroke weight for the entire curve based on the threshold value `t`
let weight = map(sin((i * 100 + frameCount) * 0.05), -1, 1, 1, 5);
strokeWeight(weight);
i++;
for (let y = 0; y < rows - 1; y++) {
for (let x = 0; x < cols - 1; x++) {
let topLeft = noiseValues[y][x];
let topRight = noiseValues[y][x + 1];
let bottomLeft = noiseValues[y + 1][x];
let bottomRight = noiseValues[y + 1][x + 1];
let caseIndex = 0;
if (topLeft >= t) caseIndex |= 1;
if (topRight >= t) caseIndex |= 2;
if (bottomRight >= t) caseIndex |= 4;
if (bottomLeft >= t) caseIndex |= 8;
let edges = getEdges(caseIndex, x, y, topLeft, topRight, bottomRight, bottomLeft, t, cellSize);
if (edges.length == 2) {
// Create a unique oscillation for each line based on x and y
// let weight = map(sin((x + y + frameCount) * 0.05), -1, 1, 1, 4);
// strokeWeight(weight);
line(edges[0].x, edges[0].y, edges[1].x, edges[1].y);
}
}
}
}
}
function getEdges(caseIndex, x, y, tl, tr, br, bl, threshold, cellSize) {
let edges = [];
switch (caseIndex) {
case 1:
case 14:
edges.push(createVector(x * cellSize, lerp(y, y + 1, (threshold - tl) / (bl - tl)) * cellSize));
edges.push(createVector(lerp(x, x + 1, (threshold - tl) / (tr - tl)) * cellSize, y * cellSize));
break;
case 2:
case 13:
edges.push(createVector(lerp(x, x + 1, (threshold - tl) / (tr - tl)) * cellSize, y * cellSize));
edges.push(createVector((x + 1) * cellSize, lerp(y, y + 1, (threshold - tr) / (br - tr)) * cellSize));
break;
case 3:
case 12:
edges.push(createVector(x * cellSize, lerp(y, y + 1, (threshold - tl) / (bl - tl)) * cellSize));
edges.push(createVector((x + 1) * cellSize, lerp(y, y + 1, (threshold - tr) / (br - tr)) * cellSize));
break;
case 4:
case 11:
edges.push(createVector((x + 1) * cellSize, lerp(y, y + 1, (threshold - tr) / (br - tr)) * cellSize));
edges.push(createVector(lerp(x, x + 1, (threshold - bl) / (br - bl)) * cellSize, (y + 1) * cellSize));
break;
case 6:
case 9:
edges.push(createVector(lerp(x, x + 1, (threshold - tl) / (tr - tl)) * cellSize, y * cellSize));
edges.push(createVector(lerp(x, x + 1, (threshold - bl) / (br - bl)) * cellSize, (y + 1) * cellSize));
break;
case 7:
case 8:
edges.push(createVector(x * cellSize, lerp(y, y + 1, (threshold - tl) / (bl - tl)) * cellSize));
edges.push(createVector(lerp(x, x + 1, (threshold - bl) / (br - bl)) * cellSize, (y + 1) * cellSize));
break;
case 10:
edges.push(createVector(lerp(x, x + 1, (threshold - tr) / (br - tr)) * cellSize, y * cellSize));
edges.push(createVector(x * cellSize, lerp(y, y + 1, (threshold - bl) / (br - bl)) * cellSize));
break;
case 5:
edges.push(createVector(x * cellSize, lerp(y, y + 1, (threshold - tl) / (bl - tl)) * cellSize));
edges.push(createVector(lerp(x, x + 1, (threshold - tr) / (br - tr)) * cellSize, y * cellSize));
edges.push(createVector((x + 1) * cellSize, lerp(y, y + 1, (threshold - br) / (bl - br)) * cellSize));
edges.push(createVector(lerp(x, x + 1, (threshold - tl) / (bl - tl)) * cellSize, (y + 1) * cellSize));
break;
}
return edges;
}