xxxxxxxxxx
68
let tileSize = 10;
let startHue;
let endHue;
let noiseScale = 0.01;
let points = [];
function setup() {
createCanvas(400, 400);
colorMode(HSB);
startHue = random(255);
endHue = random(255);
generatePoints();
noLoop();
strokeWeight(1);
}
function draw() {
background(0);
for(let p of points) {
petal(p.x, p.y, p.z);
}
}
function generatePoints() {
points = [];
for(let i = 0; i < width; i += tileSize) {
for(let j = 0; j < height; j += tileSize) {
let n = noise(i * noiseScale, j * noiseScale);
n = n * n;
points.push(createVector(i, j, n));
}
}
points.sort((a, b) => { return a.z - b.z });
}
function petal(x, y, depth) {
push();
translate(x, y);
const h = lerp(startHue, endHue, depth);
fill(h, 255, 255 * depth);
stroke(h, 200, 255 * depth - 50);
beginShape();
const n = 8;
for(let i = 0; i < n; i ++) {
const a = TAU/n * i;
const r = tileSize * random(0.5, 1);
if(i === 0 || i === n-1) {
vertex(cos(a) * r, sin(a) * r);
}
curveVertex(cos(a) * r, sin(a) * r);
}
endShape(CLOSE);
pop();
}