xxxxxxxxxx
let outerAmount = 5;
let outerStars = [];
let innerAmount = 3;
let innerStars = [];
function setup() {
createCanvas(600, 600);
colorMode(HSB);
strokeWeight(50);
for (let i = 0; i < outerAmount; i++) {
outerStars.push(new Star(30, (TWO_PI / outerAmount) * i, -0.003));
}
for (let i = 0; i < innerAmount; i++) {
innerStars.push(new Star(10, (TWO_PI / innerAmount) * i, 0.005));
}
describe('A colorful oscillating star.');
}
function draw() {
background(10);
translate(width / 2, height / 2);
for (let star of outerStars) {
star.update();
}
for (let star of innerStars) {
star.update();
}
for (let [i, outStar] of outerStars.entries()) {
for (let inStar of innerStars) {
stroke((360 / outerStars.length) * i, 100, 100, 0.5);
push();
blendMode(SCREEN);
line(outStar.x, outStar.y, inStar.x, inStar.y);
pop();
}
}
}
class Star {
constructor(initialR, a, delta) {
this.initialR = initialR;
this.a = a;
this.delta = delta;
}
update() {
this.a += this.delta;
this.r = this.initialR * sin(this.a * 5) * 8 + this.initialR;
this.x = this.r * cos(this.a);
this.y = this.r * sin(this.a);
}
}