xxxxxxxxxx
57
let things = []
const numThings = 100
function setup() {
createCanvas(800, 800);
for (let w = 0; w < 10; w++){
for (let h = 0; h < 10; h++){
things.push(new Thing(w*windowHeight/10, h*windowWidth/10))
}
}
}
function draw() {
let bgColor = color(255,255,255);
bgColor.setAlpha(.99999);
//background(bgColor)
for (let i = 0; i < things.length; i++){
things[i].move()
things[i].draw()
}
}
class Thing {
constructor(x, y) {
this.px = random(x);
this.py = random(y);
this.x = random(x);
this.y = random(y);
this.diameter = random(10, 30);
this.speed = 1;
}
move() {
this.x += random(-10,10);
this.y += random(-10,10);
if (this.x > windowWidth || this.x < 0){
this.x = random(0, windowWidth)
this.px = this.x;
}
if (this.y > windowHeight || this.y < 0){
this.y = random(0, windowHeight)
this.py = this.y;
}
}
draw() {
let strokeColor;
strokeColor = (round(random(0,1)) == 0) ? color(0,0,255) : color(255,255,255);
strokeColor.setAlpha(128 * sin(millis() / 5));
stroke(strokeColor);
line(this.px, this.py, this.x, this.y);
this.px = this.x;
this.py = this.y;
}
}