let nStars = 100;
let img1, img2;
let stars;
let condition;
function preload() {
img1 = loadImage("/assets/condition.jpg");
img2 = loadImage("/assets/star.png");
}
function setup() {
createCanvas(600, 600);
nStars = int(random(100,300))
angleMode(DEGREES);
image(img1, 0, 0, 840, 840);
noStroke();
background(img1);
imageMode(CENTER);
stars = [];
w = 3;
for(let i = 0;i<nStars;i++){
stars.push(new Star())
}
condition = true;
cnt=0
}
function draw() {
translate(width / 2, height / 2);
t1 = frameCount / 30;
push();
rotate(t1);
image(img1, 0, 0, 800, 800);
pop();
for(let i = 0;i<stars.length;i++){
stars[i].display();
}
tArray = []
for(let i = 0;i<stars.length;i++){
tArray[i] = stars[i].inCenter
}
condition = tArray.includes(false)
if(!condition){
for(let i =0;i< stars.length;i++){
stars[i].r+=stars[i].speed*random(1,3)
push()
translate(stars[i].r*cos(stars[i].angle) - stars[i].size/2, stars[i].r*sin(stars[i].angle)-stars[i].size/2)
rotate(-stars[i].speed*t1)
image(img2,0,0,stars[i].size,stars[i].size)
pop()
}
}
again = []
for(let i = 0;i<stars.length;i++){
again[i]= stars[i].r>200;
}
if(!again.includes(false)){
for(let i = 0;i<stars.length;i++){
stars[i].inCenter = false;
stars[i].speed = random(0.1,1)
}
}
}
class Star{
constructor(){
this.r = random(0,width/2)
this.angle = random(0 ,360)
this.size = randomGaussian(10,5)
this.speed = random(0.2,0.8)
this.inCenter = false
}
display(){
if(!this.inCenter){
push()
translate(this.r*cos(this.angle) - this.size/2, this.r*sin(this.angle)-this.size/2)
rotate(-this.speed*t1)
image(img2,0,0,this.size,this.size)
pop()
}
this.angle+=this.speed
if(this.r>10 && !this.inCenter){
this.r-=this.speed
}else{
this.r = this.r
this.inCenter=true
}
}
}