xxxxxxxxxx
52
class Star {
constructor(colorValue) {
this.colorValue = colorValue;
}
}
let starArray = [];
let r = 200;
function setup() {
createCanvas(700, 700, WEBGL);
angleMode(DEGREES); // degrees for easier calculations
colorMode(RGB);
frameRate(30);
strokeWeight(3);
noFill();
for (let i = 0; i < 360; i++) {
// let randomColorValue = int(random(100));
// console.log(randomColorValue);
// if (randomColorValue > 50) {
starArray.push(new Star(255));
// } else {
// starArray.push(new Star(0));
// }
}
}
function draw() {
rotateX(frameCount % 360);
rotateY(frameCount % 360);
background(0);
orbitControl(4, 4); // allows rotation + value 4 is for the speed of the rotation or perhaps how much the camera rotates per "mouse swipe"
for (let a1 = 0; a1 < 180; a1 += 5) {
//a1 = phi
beginShape(POINTS);
for (let a2 = 0; a2 < 360; a2 += 5) {
//a2 = theta
let x = r * (3 + 1 * sin(a2 * 6) * cos(a1 * 9)) * cos(a1);
let y = r * (3 + 1 * sin(a2 * 6) * cos(a1 * 9)) * sin(a1) * sin(a2);
let z = r * (3 + 1 * sin(a2 * 6) * cos(a1 * 9)) * sin(a1) * cos(a2);
stroke(starArray[a2].colorValue);
vertex(x, y, z);
}
endShape(CLOSE);
}
}