xxxxxxxxxx
57
let p = [];
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
function setup() {
createCanvas(windowWidth, windowHeight);
}
function draw() {
background(220);
noFill();
while(p.length < 35) p.push(pen());
p.map(x => penOutOfBounds(x) ? penKill(x) : penTraverse(x));
p = p.filter(({past}) => !penOutOfBounds(x) && past.length > 0);
p.map(x => penRender(x));
}
function penKill({past}) {
if(past.length > 0) past.shift();
}
function penOutOfBounds({x,y}) {
return x < 0 || x > windowWidth || y < 0 || y > windowHeight;
}
function penTraverse(pen) {
({x,y,ang,t,past, speed, noiseStep, steer} = pen);
past.push({x,y});
if(past.length > 100) past.shift();
pen.x += cos(ang) * speed;
pen.y += sin(ang) * speed;
pen.ang += map(noise(t),0,1,-steer,steer);
pen.t += noiseStep;
}
function penRender({past,col}) {
stroke(col);
beginShape();
past.map(({x,y}) => vertex(x,y));
endShape();
}
function pen() {
return {
past: [],
t: random(100),
ang: random(2 * PI),
speed: random(3,5),
steer: PI * 0.25,
noiseStep: random(0.01,0.01),
col: random([color(255,0,0), color(255,0,255), color(0,0,0)]),
x: random(windowWidth),
y: random(windowHeight)
}
}