xxxxxxxxxx
76
let star = [];
let numberOfStars = 300;
let a = 0;
function setup() {
createCanvas(windowWidth, windowHeight/1.15);
angleMode(DEGREES);
noCursor();
noStroke();
for(let i=0; i<numberOfStars; i++){
star.push (new Star(i*20+40,i*22,5));
}
}
function draw() {
background(0);
for(let i=0;i<star.length;i++){
star[i].show();
star[i].fallToCentre();
star[i].reset();
star[i].spiral();
}
}
function Star(X,Y,S){
this.ang = random(0,360);
this.radius = random(windowWidth/2,windowWidth);
this.x = 0;
this.y = 0;
this.xSpeed = random(-5,10);
this.ySpeed = random (-5,10);
this.size = 2;
this.rotate = 0;
this.r = random(180,255);
this.g = random(180,255);
this.b = random(180,255);
this.show = function(){
this.x = sin(this.ang)*this.radius;
this.y = cos(this.ang)*this.radius;
push();
translate(mouseX,mouseY);
rotate(this.rotate);
fill(this.r,this.g,this.b);
ellipse(this.x,this.y,this.size);
pop();
}
this.fallToCentre = function(){
this.radius = this.radius-1;
this.size = this.radius*0.01;
}
this.spiral = function(){
this.rotate+= 0.1;
if(this.radius<100){
this.rotate += 0.75;
}
if(this.radius<275){
this.rotate += 0.5;
}
if(this.radius<500){
this.rotate += 0.25;
}
}
this.reset = function(){
if(this.radius<50){
this.radius = 650;
}
}
}