xxxxxxxxxx
38
let pts = [];
function setup() {
createCanvas(800, 800);
for (let _ = 0; _ < 100; _++) {
pts.push({
x:random(1,width-2),
vx:random([-1,1]),
base_y: random(height*0.08, height*0.5),
a: random(width*0.05, width*0.25),
f: random(.00025, .025),
})
}
// rectMode(CENTER);
}
function draw() {
background(20);
fill(color(220,220,220,80));
noStroke();
for (let p of pts) {
let y = p.base_y + p.a*sin(p.f * p.x);
rect(p.x-2.5, y, 5, height);
circle(p.x,y,5);
// line(p.x, y, p.x, height);
p.x += p.vx;
if (p.x < 0) {
p.x = 0;
p.vx *= -1;
} else if (p.x > width-1) {
p.x = width-1;
p.vx *= -1;
}
}
}