Processing 4.3 (java Mode) Full Solar System Utc Cordinated
by nikhilboddeda2013 in Design > Digital Graphics
13 Views, 0 Favorites, 0 Comments
Processing 4.3 (java Mode) Full Solar System Utc Cordinated
I have made this solar system full in processing (java mode) and it uses utc live and info ordits and all controlls like speed of ordit click on orbit and the planet info comes with drafts .i have made this for a school project
Supplies
download processing 4.3
computer
and python download on processing app
download py java file given
Download Processing 4.3
download from here(https://processing.org/download)
Open the Script
open the script java mode
Copy This Code Exactly
import java.time.*;
// ⭐ Stars
int STAR_COUNT = 400;
float[] starX = new float[STAR_COUNT];
float[] starY = new float[STAR_COUNT];
ArrayList<Planet> planets = new ArrayList<Planet>();
Planet selectedPlanet;
boolean sunSelected = false;
// Speed slider
float speedMultiplier = 20;
float sliderX = 120;
float sliderY = 760;
float sliderW = 300;
boolean dragging = false;
// Sun info
float sunX, sunY, sunSize;
float sunTemp = 5778; // Kelvin
float sunRadius = 696340; // km
double sunAgeBillionYears = 4.603;
class Planet {
String name;
int moons;
float distance, size, yearDays;
color c;
float angle;
float speed;
double ageBillionYears;
Planet(String n, float d, float s, float y, int m, color col, double age) {
name = n;
distance = d;
size = s;
yearDays = y;
moons = m;
c = col;
angle = random(TWO_PI);
speed = TWO_PI / yearDays;
ageBillionYears = age;
}
void update() {
angle += speed * speedMultiplier * 0.005;
}
void drawPlanet() {
float cx = width/2;
float cy = height/2;
float x = cx + cos(angle) * distance;
float y = cy + sin(angle) * distance;
// Orbit hover highlight
float d = dist(mouseX, mouseY, cx, cy);
if (abs(d - distance) < 8) stroke(0, 255, 255);
else stroke(120);
noFill();
ellipse(cx, cy, distance*2, distance*2);
// Planet
fill(c);
noStroke();
ellipse(x, y, size, size);
// Moons
drawMoons(x, y);
// Name
fill(255);
textAlign(CENTER);
text(name, x, y - size - 5);
}
void drawMoons(float planetX, float planetY) {
if (moons <= 0) return;
float moonDistance = size + 4;
for (int i = 0; i < moons; i++) {
float moonAngle = angle + i * TWO_PI / moons + millis() * 0.001;
float mx = planetX + cos(moonAngle) * moonDistance;
float my = planetY + sin(moonAngle) * moonDistance;
fill(200);
noStroke();
ellipse(mx, my, 4, 4);
}
}
boolean orbitClicked(float mx, float my) {
float d = dist(mx, my, width/2, height/2);
return abs(d - distance) < 8;
}
float orbitPositionDegrees() {
return degrees(angle) % 360;
}
float yearInEarthYears() {
return yearDays / 365.0;
}
double ageInEarthYears() {
return ageBillionYears * 1_000_000_000;
}
}
void setup() {
size(1200, 800);
textSize(14);
sunX = width/2;
sunY = height/2;
sunSize = 60;
// ⭐ Generate stars
for (int i = 0; i < STAR_COUNT; i++) {
starX[i] = random(width);
starY[i] = random(height);
}
// Planets
planets.add(new Planet("Mercury", 80, 8, 88, 0, color(200), 4.503));
planets.add(new Planet("Venus", 120, 12, 225, 0, color(255, 200, 0), 4.503));
planets.add(new Planet("Earth", 170, 14, 365, 1, color(0, 120, 255), 4.543));
planets.add(new Planet("Mars", 220, 12, 687, 2, color(255, 80, 80), 4.603));
planets.add(new Planet("Jupiter", 320, 30, 4333, 95, color(255, 160, 120), 4.503));
planets.add(new Planet("Saturn", 400, 26, 10759, 146, color(210, 190, 140), 4.503));
// Draft planets
planets.add(new Planet("Planet X", 500, 20, 5000, 3, color(150, 150, 255), 1.2));
planets.add(new Planet("Planet Y", 600, 18, 6000, 0, color(255, 100, 255), 0.8));
}
void draw() {
background(0);
drawStars(); // ⭐ draw stars first
// Sun
fill(255, 200, 0);
noStroke();
ellipse(sunX, sunY, sunSize, sunSize);
for (Planet p : planets) {
p.update();
p.drawPlanet();
}
drawSlider();
drawUTCClock();
if (sunSelected) drawSunInfo();
if (selectedPlanet != null) drawPlanetInfo(selectedPlanet);
}
// ⭐ Draw stars
void drawStars() {
noStroke();
fill(255);
for (int i = 0; i < STAR_COUNT; i++) {
ellipse(starX[i], starY[i], 2, 2);
}
}
void mousePressed() {
if (mouseY > sliderY-10 && mouseY < sliderY+10 &&
mouseX > sliderX && mouseX < sliderX + sliderW) {
dragging = true;
}
selectedPlanet = null;
sunSelected = false;
if (dist(mouseX, mouseY, sunX, sunY) < sunSize/2) {
sunSelected = true;
return;
}
for (Planet p : planets) {
if (p.orbitClicked(mouseX, mouseY)) {
selectedPlanet = p;
break;
}
}
}
void mouseDragged() {
if (dragging) {
speedMultiplier = map(mouseX, sliderX, sliderX + sliderW, 5, 50);
speedMultiplier = constrain(speedMultiplier, 5, 50);
}
}
void mouseReleased() {
dragging = false;
}
void drawSlider() {
stroke(255);
line(sliderX, sliderY, sliderX + sliderW, sliderY);
float knobX = map(speedMultiplier, 5, 50, sliderX, sliderX + sliderW);
fill(255);
ellipse(knobX, sliderY, 12, 12);
fill(255);
textAlign(LEFT);
text("Speed", sliderX - 60, sliderY + 5);
}
void drawUTCClock() {
ZonedDateTime utc = ZonedDateTime.now(ZoneOffset.UTC);
fill(255);
textAlign(RIGHT);
text("UTC Time: " + utc.toString().substring(0, 19), width - 20, 30);
}
void drawPlanetInfo(Planet p) {
float infoW = 440;
float infoH = 260;
fill(0, 210);
rect(20, 20, infoW, infoH, 10);
fill(255);
textAlign(LEFT);
textSize(14);
text("Planet: " + p.name, 40, 55);
text("Moons: " + p.moons, 40, 85);
text("Year length: " + p.yearDays + " Earth days", 40, 115);
text("≈ " + nf(p.yearInEarthYears(), 1, 2) + " Earth years", 40, 140);
text("Age: " + p.ageBillionYears + " billion years", 40, 170);
text("Orbit position: " + nf(p.orbitPositionDegrees(), 1, 2) + "°", 40, 200);
}
void drawSunInfo() {
float infoW = 400;
float infoH = 220;
fill(0, 210);
rect(20, 20, infoW, infoH, 10);
fill(255);
textAlign(LEFT);
textSize(14);
text("Sun Information", 40, 55);
text("Surface Temperature: " + sunTemp + " K", 40, 85);
text("Radius: " + sunRadius + " km", 40, 115);
text("Age: " + sunAgeBillionYears + " billion years", 40, 145);
text("Luminosity: ≈ 3.828 × 10^26 W", 40, 175);
}
Now Paste This Code in the Editor
paste the code
Run the Code the Play Button
run the code
Or Down the Procssing File I Give and Open It in Processing
Downloads
Done Explore It
it is a great project