xxxxxxxxxx
62
let swarm = [];
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 100);
let num = width*0.02
for (let i = 0; i < num; i++){
swarm.push(new Screen());
}
frameRate(20);
}
function draw() {
background(random(80,120), 50, 100, 50);
for (let i = 0; i < swarm.length; i++){
swarm[i].update();
swarm[i].display();
}
}
class Screen{
constructor(){
this.angle = createVector();
this.vel = createVector(0, 0);
this.amp = createVector(random(20, width/2), random(20, height/2));
this.H1 = random(200,300);
this.H2 = random(0,50);
this.rad = random(height*.02, height*.05);
this.len = random(4, 6);
}
update(){
this.accel = createVector(random(-0.01, 0.01), random(-0.01, 0.01));
//this.accel = p5.Vector.random2D();
this.vel.add(this.accel);
this.angle.add(this.vel);
}
display(){
let x = sin(this.angle.x) * this.amp.x;
let y = sin(this.angle.y) * this.amp.y;
push();
translate(width/2, height/2);
stroke(this.H1, random(100), random(100));
noFill();
//fill(random(30,100), random(100), random(100));
for (let i = 0; i < this.rad; i++){
circle(x, y, this.len * i);
}
pop();
stroke(this.H2, random(100), random(100));
line(mouseX, mouseY, x*(width/2), y*(height/2));
//circle(x, y, 32);
//pop();
}
}