Public
Edited
Feb 2, 2023
2 forks
6 stars
Insert cell
Insert cell
Insert cell
p5((s) => {
let system, H, W;
W = form.width;
H = form.height;

// Color
let bg, c1, c2, c3, c4;
bg = getColor();
c1 = s.color(getColor());
c2 = s.color(getColor());
c3 = s.color(getColor());
c4 = s.color(getColor());
// Rest of the variables
let x, y, nfx, wh, nf, ct;

// Setup function ///////////////////////////////////////////////////////
s.setup = function () {
s.createCanvas(W, H);
s.noStroke();
nf = form.nf;
ct = 0;
};

// Draw function ///////////////////////////////////////////////////////
s.draw = function () {
ct = 0;
while (ct < 100) {
x = s.random(W);
y = s.random(H);
nfx = s.noise(x * nf, y * nf);
s.push();
s.translate(x, y);
s.rotate(Math.PI * nfx);

wh = s.random(form.scale) * s.sin(0.02 * s.frameCount);

if (nfx < 0.1) {
s.fill(c1);
noisy_rect(0, 0, wh, wh, 1);
}
if (nfx > 0.1 && nfx < 0.2) {
s.fill(c2);
noisy_rect(0, 0, wh, wh, 1);
}
if (nfx > 0.2 && nfx < 0.3) {
s.fill(c3);
noisy_rect(0, 0, wh, wh, 1);
}
if (nfx > 0.3 && nfx < 0.4) {
s.fill(c4);
noisy_rect(0, 0, wh, wh, 1);
}
if (nfx > 0.4 && nfx < 0.5) {
s.fill(c1);
noisy_rect(0, 0, wh, wh, 1);
}

if (nfx > 0.5 && nfx < 0.6) {
s.fill(c2);
noisy_rect(0, 0, wh, wh, 1);
}

if (nfx > 0.6 && nfx < 0.7) {
s.fill(c3);
noisy_rect(0, 0, wh, wh, 2);
}

if (nfx > 0.7 && nfx < 0.8) {
s.fill(c4);
noisy_rect(0, 0, wh, wh, 2);
}

if (nfx > 0.8 && nfx < 0.9) {
s.fill(c1);
noisy_rect(0, 0, wh, wh, 2);
}

if (nfx > 0.9) {
s.fill(c2);
noisy_rect(0, 0, wh, wh, 2);
}

s.pop();
ct += 1;
}
};

// Noisy Rectangle function ///////////////////////////////////////////////////////
const noisy_rect = (x, y, w, h, r) => {
s.noStroke();
let cnt = 0;
while (cnt < 100) {
let ix = s.random(w);
let iy = s.random(h);
s.ellipse(ix, iy, r, r);
cnt += 1;
}
};
})
Insert cell
Insert cell
Insert cell
Insert cell
import { p5 } from "@tmcw/p5"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more