xxxxxxxxxx
149
let stars = [];
let planets = [];
let starColors = ['#ffd27d', '#ffa371', '#bfc2ff', '#fffa86', '#faf7ff'];
let bools = [true, false];
let color1 = ['#fcb52d', '#0092cc', '#a6a8ff', '#f2837c'];
let color2 = ['#ffde9e', '#9ee8ff', '#3d42ff', '#d92d21'];
let colors = [color1, color2];
let neb_number = 538;
let myFont;
function preload() {
myFont = loadFont('courbd.ttf');
}
function setup() {
createCanvas(640, 640, WEBGL);
angleMode(DEGREES);
textFont(myFont);
for (let i = 0; i < 100; i++) {
stars[i] = new Star();
}
}
function draw() {
background('#00004D');
for (let i = 0; i < stars.length; i++) {
stars[i].show();
}
for (let i = 0; i < planets.length; i++) {
if(random(bools)){
planets[i].ringAngle += 10000.0 / (1000 * planets[i].angleRate);
}
planets[i].show();
}
textSize(20);
textAlign(RIGHT);
textStyle(BOLD);
//italicized
textStyle(BOLD);
text('NEBULA NGC ' + neb_number, width / 2 - 20, width / 2 - 60);
text('PICTURE TAKEN BY HUBBLE', width / 2 - 20, width / 2 - 20);
text(year() + ':'+ day() + ':' + hour() + ':' + minute() + ':' +second(), width / 2 - 20, width / 2 - 40);
}
function mousePressed() {
stars = [];
for (let i = 0; i < 100; i++) {
stars[i] = new Star();
}
planets = [];
for(let i = 0; i < 15; i++){
planets[i] = new Planet();
}
neb_number = int(random(500, 600));
}
function windowResized() {
if (fullscreen) {
resizeCanvas(windowWidth, windowHeight);
} else {
resizeCanvas(640, 400)
}
}
class Star {
constructor() {
this.x = random(0, width);
this.y = random(0, height);
this.r = random(height * 0.003, height * 0.009);
this.color = random(starColors);
}
show() {
push();
translate(-width/2, -height/2, 0);
fill(this.color);
noStroke();
circle(this.x, this.y, this.r * 2);
pop();
}
}
class Planet {
constructor() {
var denom = 9;
this.x = random(width/denom, width/denom * (denom - 1));
this.y = random(height/denom, height/denom * (denom - 1));
this.z = random(-height/denom * (denom - 1), height/denom * (denom - 1));
this.r = random(height * 0.01, height * 0.1);
this.baseColor = random(color1);
this.accentColor = random(color2);
if(random(bools)){
this.baseColor = random(color2);
this.accentColor = random(color1);
}
this.ringAngle = random(-20, 20);
this.ringState = random(bools);
this.ringR = this.r * int(random(0, 10)) / 3;
this.angleRate = int(random(0, 10));
this.showStroke = random(bools);
this.ringStroke = int(random(0, 7));
this.ringAdjustX = int(random(10, 20));
}
show() {
//planet base
push();
translate(-width/2, -height/2, 0);
translate(this.x, this.y, this.z);
rotateY(this.ringAngle);
rotateX(this.ringAngle);
rotateZ(this.ringAngle);
fill(this.baseColor);
if(this.showStroke){
stroke(this.accentColor);
}
else{
noStroke();
}
sphere(this.r);
if(this.ringState){
torus(this.ringR , this.ringStroke, this.ringAdjustX, 12);
}
sphere(10);
pop();
}
contains(planetx, planety) {
let d = dist(planetx, planety, this.x, this.y);
if (d < this.r) {
return true;
} else {
return false;
}
}
}