Solar system with multiple planets

Hi,
I’m just starting out with processing and I’m trying to build a little solar system. My problem is that I don’t know how to add another planet (like mars or venus).
Because if I just ad the planet to my code it will rotate around the planet that came before.
Here is my code:
(It’s spanish luna=moon, tierra=earth, sol=sun, luz=light)

int a=200;
int h=hour();
PImage background;

PImage sol;
PShape PSol;

PImage tierra;
PShape PTierra;

PImage luna;
PShape PLuna;

void setup() {
size(1080, 2075, P3D);
//background = loadImage(“fondoX.jpg”);
//background.resize(1080, 2075);

//setup sol
sol=loadImage(“sol2k.jpg”);
sol.resize(1080, 2075);
PSol= createShape(SPHERE, 70);
PSol.setTexture(sol);
PSol.setStroke(false);

//setup tierra
tierra=loadImage(“tierra3.jpg”);
tierra.resize(1080, 2075);
PTierra= createShape(SPHERE, 35);
PTierra.setTexture(tierra);
PTierra.setStroke(false);

//setup luna
luna=loadImage(“luna2k.jpg”);
luna.resize(1080, 2075);
PLuna= createShape(SPHERE, 11);
PLuna.setTexture(luna);
PLuna.setStroke(false);
}

void draw() {

//background(background);
background(#020B22);
noFill();
noStroke();
sphereDetail(10);

//sol
translate(540, 1000, 0);
rotateY(a * 0.003);
//rotateY(mouseX * 0.007);
shape(PSol);

//luz
pointLight(255, 255, 255, 0, 0, 0);
translate(0, 0, 300);
//noLights();
ambientLight(45, 65, 75);
pointLight(255, 255, 255, 0, 0, -150);

//tierra
translate(230, 0, 0);
rotateY(a * 0.02);
// rotateY(mouseX * 0.02);
shape(PTierra);

//luna
translate(90, 0, 0);
shape(PLuna);

a=a+1;
}

you can isolate the movement (of the planets from each other) by using pushMatrix() and popMatrix() around each planet’s code section

//sol
pushMatrix(); // store a blank / fresh situation of the Matrix
translate(540, 1000, 0);  // change Matrix
rotateY(a * 0.003);
//rotateY(mouseX * 0.007);
shape(PSol);
popMatrix();  // restore the fresh Matrix from before 

Thanks!
It’s working now and I added a few more planets.

1 Like