xxxxxxxxxx
48
let center_x;
let center_y;
let all_stars = [];
function setup() {
createCanvas(700, 700);
background(0);
center_x = width/2;
center_y = height/2;
for (let i = 0; i < 100; i++) {
let star = new Star();
all_stars[i] = star;
}
for (let i = 0; i < all_stars.length; i++) {
all_stars[i].show();
}
angleMode(DEGREES);
}
function draw() {
for (let i = 0; i < all_stars.length; i++) {
let current_star = all_stars[i];
current_star.xpos = center_x + current_star.radius * cos(current_star.angle);
current_star.ypos = center_y + current_star.radius * sin(current_star.angle);
current_star.show();
current_star.angle += 0.1;
}
}
class Star {
constructor() {
this.radius = random(width/2);
this.xpos = center_x + random(-this.radius, this.radius)*1;
this.ypos = center_y + random(-this.radius, this.radius)*2;
this.angle = abs((center_y - this.ypos)/(center_x - this.xpos));
}
show() {
//let clr = color(random(100, 255), random(100, 255), random(100, 255));
fill("yellow");
circle(this.xpos, this.ypos, random(1, 6));
}
}