let stars = []; let angle = 0; let earthRotation = 0; function setup() { createCanvas(800, 600); for (let i = 0; i < 500; i++) { stars.push({ x: random(width), y: random(height), size: random(1, 3), speed: random(0.1, 0.5) }); } } function draw() { background(2, 5, 15); // --- Background Stars --- fill(255); noStroke(); for (let star of stars) { ellipse(star.x, star.y, star.size); star.x -= star.speed; if (star.x < 0) star.x = width; } translate(width / 2, height / 2); // --- 1. Draw Earth --- drawEarth(200); // --- 2. Draw Moon --- push(); rotate(angle * 0.3); // Moon moves slower than the station translate(300, 0); // Moon distance drawMoon(70); pop(); // --- 3. Draw Space Station --- push(); rotate(angle); translate(200, 0); rotate(-angle); // Keep upright drawStation(); pop(); angle += 0.01; earthRotation += 0.005; // The speed of the day/night cycle } function drawEarth(d) { push(); // Base Ocean fill(10, 40, 120); noStroke(); ellipse(0, 0, d, d); // Rotating Surface (Land and Lights) push(); rotate(earthRotation); // Irregular Landmasses fill(40, 120, 50); drawLand(-70,-60, 1.3);//north america drawLand(-65,2, 1.2);//south america drawLand(10, -0, 1.1);//africa drawLand(10,-60,1 );//europe drawLand(40, -30, 1.3);//asia drawLand(-20, 50, 1);//an pop(); // THE SHADOW (Day/Night Mask) // This stays still while the Earth rotates underneath it fill(0, 0, 0, 180); arc(0, 0, d+2, d+2, -HALF_PI, HALF_PI, CHORD); // Darkens the right side // Atmosphere Rim noFill(); stroke(100, 180, 255, 80); strokeWeight(3); ellipse(0, 0, d, d); pop(); } function drawLand(x, y, s) { push(); translate(x, y); scale(s); beginShape(); vertex(0, 0); vertex(20, -10); vertex(40, 5); vertex(35, 30); vertex(10, 45); vertex(-15, 25); vertex(-5, 10); endShape(CLOSE); pop(); } function drawMoon(d) { // Moon Body fill(180); noStroke(); ellipse(0, 0, d, d); // Craters fill(150); ellipse(-d*0.2, -d*0.1, d*0.2); ellipse(d*0.1, d*0.2, d*0.15); ellipse(d*0.3, -d*0.2, d*0.1); // Moon Shadow fill(0, 120); arc(0, 0, d, d, -HALF_PI, HALF_PI, CHORD); } function drawStation() { fill(220); stroke(50); rectMode(CENTER); rect(0, 0, 30, 10); // Core fill(0, 80, 180); rect(-25, 0, 20, 40); // Solar Left rect(25, 0, 20, 40); // Solar Right }