xxxxxxxxxx
47
let star = [];
function setup() {
createCanvas(800, 600);
strokeWeight(10);
for(let i=0;i<10;i++){
star.push(new Star());
}
}
function draw() {
background(200);
for(let i=0;i<star.length;i++){
star[i].show();
star[i].fallToCentre();
star[i].reset();
}
}
function Star(){
this.ang = random(0,TWO_PI);
this.radius = random(100,200);
this.x = 0;
this.y = 0;
this.show = function(){
this.x = sin(this.ang)*this.radius+mouseX;
this.y = cos(this.ang)*this.radius+mouseY;
point(this.x,this.y);
}
this.fallToCentre = function(){
this.radius = this.radius-1;
}
this.reset = function(){
if(this.radius<0){
this.radius = 200;
}
}
}