xxxxxxxxxx
var bug1=[];
//var rr =random(this.location.x)*255;
function setup(){
createCanvas(windowWidth,windowHeight);
for(var i =0;i<20000;i++){
bug1[i] = new Jitter();
}
}
function draw(){
background(255,255,255,25);
for(var i=0;i<bug1.length;i++){
bug1[i].move();
bug1[i].display();
bug1[i].checkEdges();
}
}
//Jitter class
function Jitter(){
this.location=new p5.Vector(random(width),random(height));
this.velocity=new p5.Vector(0,0);
this.acceleration=new p5.Vector(0,0);
/*this.x=random(width);
this.y=random(height);
this.xspeed=2;
this.yspeed=-2;*/
this.diameter=random(5,20);
this.move=function(){
this.mouse = new p5.Vector(mouseX,mouseY);
this.mouse.sub(this.location);
this.mouse.setMag(0.005);
this.acceleration=this.mouse;
//this.acceleration= p5.Vector.random2D();
this.location.add(this.velocity);
this.velocity.add(this.acceleration);
this.velocity.limit(2);
//this.x +=this.xspeed;
//this.y +=this.yspeed;
}
this.checkEdges=function(){
if(this.location.x>width || this.location.x<0){
this.velocity.x=this.velocity.x*-1;}
if(this.location.y>height || this.location.y<0){
this.velocity.y=this.velocity.y*-1;}
}
this.display=function(){
//fill(255,30);
//stroke(100,30);
strokeWeight(2);
point(this.location.x,this.location.y);}
//ellipse(this.location.x,this.location.y,this.diameter,this.diameter);}
}