xxxxxxxxxx
95
let a;
let b;
function wiggleLine(x1, y1, x2, y2) {
const xo = random(10000, 20000);
let d = dist(x1, y1, x2, y2);
let nx = (y1 - y2) / d;
let ny = (x2 - x1) / d;
for (let idx = 0; idx < 40; ++idx) {
const x = map(idx, 0, 40, x1, x2);
const y = map(idx, 0, 40, y1, y2);
const o = lerp(-1.5, 1.5, noise(xo + idx / 5.0));
curveVertex(x + o * nx, y + o * ny);
}
}
function wiggleRect(w, h) {
const w2 = w / 2;
const h2 = h / 2;
const pts = [
random(-w2 - 5, -w2 + 5),
random(h2 - 5, h2 + 5),
random(w2 - 5, w2 + 5),
random(h2 - 5, h2 + 5),
random(w2 - 5, w2 + 5),
random(-h2 - 5, -h2 + 5),
random(-w2 - 5, -w2 + 5),
random(-h2 - 5, -h2 + 5),
];
beginShape();
for (let idx = 0; idx < 4; ++idx) {
wiggleLine(
pts[2 * idx],
pts[2 * idx + 1],
pts[(2 * idx + 2) % 8],
pts[(2 * idx + 3) % 8]
);
}
endShape(CLOSE);
}
function setup() {
createCanvas(480, 720);
a = color("#0057b7");
b = color("#ffd700");
background(230, 230, 225);
noStroke();
rectMode(CENTER);
const rects = [
[a, 0.25, 0.5],
[b, 0.5, 0.75],
];
x = int(random(2));
for (let idx = 0; idx < 2; ++idx) {
let r = rects[x];
fill(r[0]);
push();
translate(width * random(0.4, 0.6), height * random(r[1], r[2]));
rotate(random(-PI / 8, PI / 8));
wiggleRect(width * random(0.6, 0.75), height * random(0.2, 0.4));
pop();
x = 1 - x;
}
loadPixels();
const d = pixelDensity();
for (let y = 0; y < height * d; ++y) {
for (let x = 0; x < width * d; ++x) {
const idx = (y * width * d + x) * 4;
let n = map(noise(x * 0.01, y * 0.01), 0, 1, 0.95, 1);
const o = random(-10, 10);
pixels[idx] = constrain(pixels[idx] * n + o, 0, 255);
pixels[idx + 1] = constrain(pixels[idx + 1] * n + o, 0, 255);
pixels[idx + 2] = constrain(pixels[idx + 2] * n + o, 0, 255);
}
}
updatePixels();
}
function keyPressed() {
if (key == "s") {
save("output.jpg");
} else if (key == " ") {
setup();
}
}