sketchvar numPlanets = 4;
var planet = {x: [], y: [], s: [], r: [], g: [], b: [], dx: []};
var d = [];
var numStars = 100;
var star = {x: [], y: [], s: [], dx: []};
var porthole;
var astroLinks = ["https://i.imgur.com/FrLKzou.png",
"https://i.imgur.com/vdhX4kE.png",
"https://i.imgur.com/01Kk3J7.png"];
var astroPics = [];
var astro = {x: [], y: [], s: [], dx: [], e: []};
function preload(){
for(k = 0; k < 3; k++){
astroPics[k] = loadImage(astroLinks[k]);
}
porthole = loadImage("https://i.imgur.com/YSSOdgW.png")}
function setup() {
createCanvas(480, 480);
background(0);
planetInitialize();
starInitialize();
astroInitialize();
}
function draw() {
background(0);
starUpdate();
planetUpdate();
astroUpdate();
image(porthole, 0, 0, width, height);
}
function drawPlanetA(x, y, s, i){ strokeWeight(0);
fill(planet.r[i], planet.g[i], planet.b[i]); ellipse(x, y, s, s);
fill(planet.r[i] + 20, planet.g[i] + 20, planet.b[i] + 20); ellipse(x - s/10, y + s/3, s/4);
ellipse(x + s/5, y - s/10, s/3);
ellipse(x - s/4, y - s/5, s/7);
}
function drawPlanetB(x, y, s, i){ fill(planet.r[i], planet.g[i], planet.b[i]);
ellipse(x, y, s, s);
strokeWeight(3);
stroke(255-planet.r[i], 255-planet.g[i], 255-planet.b[i]);
line(x - s*(2/3), y, x + s*(2/3), y);
strokeWeight(0);
}
function starUpdate(){
for(var j = 0; j < numStars; j++){
strokeWeight(0)
fill(250, 248, 235); ellipse(star.x[j], star.y[j], star.s[j], star.s[j]);
if(star.x[j] >= width + star.s[j]){ star.s[j] = random(1, 10);
star.x[j] = random(-20, 0-star.s[j]); star.y[j] = random(0, height);
star.dx[j] = star.s[j] / 200;
}else{
star.x[j] += star.dx[j]; }
}
}
function planetUpdate(){
for(var i = 0; i < numPlanets; i++){
if(d[i] <= 1){ drawPlanetA(planet.x[i], planet.y[i], planet.s[i], i);
}else if(d[i] > 1){
drawPlanetB(planet.x[i], planet.y[i], planet.s[i], i);
}
if(planet.x[i] >= width + planet.s[i] + (planet.s[i] * (2/3))){ planet.s[i] = random(10, 150);
planet.x[i] = random(-200, 0-planet.s[i]); planet.y[i] = random(0, height);
planet.r[i] = random(20, 235);
planet.g[i] = random(20, 235);
planet.b[i] = random(20, 235);
planet.dx[i] = planet.s[i] / 200;
}else{
planet.x[i] += planet.dx[i]; }
}
}
function astroUpdate(){
for(var k = 0; k < 3; k++){
image(astroPics[k], astro.x[k], astro.y[k], astro.s[k], astro.s[k]);
if(astro.x[k] >= astro.e[k]){
astro.x[k] = random(-2000, -150);
astro.y[k] = random(0, height);
astro.s[k] = random(30, 400);
astro.dx[k] = astro.s[k] / 200;
astro.e[k] = random(height+150, 2000);
}else{
astro.x[k] += astro.dx[k];
}
}
}
function planetInitialize(){
for(var i = 0; i < numPlanets; i++){
planet.x[i] = random(0, width); planet.y[i] = random(0, height); planet.s[i] = random(10, 150); planet.r[i] = random(20, 235); planet.g[i] = random(20, 235);
planet.b[i] = random(20, 235);
planet.dx[i] = planet.s[i] / 200; d[i] = (random(0, 2)); }
}
function starInitialize(){
for(var j = 0; j < numStars; j++){
star.x[j] = random(0, width);
star.y[j] = random(0, height);
star.s[j] = random(1, 10);
star.dx[j] = star.s[j] / 200; }
}
function astroInitialize(){
for(var k = 0; k < 3; k++){
astro.x[k] = random(-2000, width)
astro.y[k] = random(0, height);
astro.s[k] = random(30, 150);
astro.dx[k] = astro.s[k] / 200;
astro.e[k] = random(height+150, 2000); }
}