xxxxxxxxxx
92
let lines, paused, colors, offset;
function keyPressed() {
if (key === " ") paused = !paused;
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
}
function setup() {
createCanvas(800, 800);
paused = false;
lines = [];
let y = 10;
let numPoints = 50;
offset = 50;
// https://kgolid.github.io/chromotome-site/ # jung-bird
colors = [
color(0, 0, 0),
color(252, 48, 50, 255),
color(254, 213, 48, 255),
color(51, 195, 251, 255),
color(255, 123, 172, 255),
color(253, 168, 41, 255),
];
for (let i = 0; i < height; i += 10) {
let points = [];
points.push(createVector(offset, y));
let first_x = offset+random(10, 30);
let last_x = width - offset-random(10, 30);
points.push(createVector(first_x, y));
let pts = (last_x - first_x) / numPoints;
for (let j = first_x; j < last_x; j += pts) {
points.push(createVector(j, y + random(-5, 5)));
}
points.push(createVector(last_x, y));
points.push(createVector(width, y));
let _c = color(0);
if (random() > 0.99) _c = colors[getRandomInt(0, colors.length)];
lines.push({
points: points,
color: _c,
first_x: first_x,
last_x: last_x,
});
y += 10;
}
}
function draw() {
if (!paused) {
background(255);
noFill();
strokeWeight(0.5);
for (let i = 0; i < lines.length; i++) {
stroke(lines[i].color);
beginShape();
for (let j = 2; j < lines[i].points.length - 2; j++) {
vertex(lines[i].points[j].x, lines[i].points[j].y);
// lines[i].points[j].x += random(0.1, 0.8);
// if (lines[i].points[j].x > lines[i].last_x)
// lines[i].points[j].x = lines[i].first_x;
// lines[i].points[j].y += random(-0.4, 0.4);
}
endShape();
if (random() > 0.99) lines[i].color = colors[getRandomInt(0,colors.length)];
}
noStroke();
fill(255);
rect(0,0,width,offset);
rect(0,0,offset,height);
rect(0,height-offset,width,offset);
rect(width-offset,0,offset,height);
}
}