ABOUT.... solar system simulation

Planet[] planets=new Planet[8];
void setup(){
  size(200,200);
  for(int i=0;i<planets.length;i++){
    planets[i]=new Planet(20+i*10,i+8);
  }
}
void draw(){
  background(255);
  pushMatrix();
  translate(width/2,height/2);
  stroke(0);
  fill(255);
  ellipse(0,0,20,20);
  for(int i=0;i<planets.length;i++){
    planets[i].update();
    planets[i].display();
  }
  popMatrix();
}
class Planet{
  float theta;
  float diameter;
  float distance;
  float orbitspeed;
  
  Planet(float distance_, float diameter_){
    distance = distance_;
    diameter = diameter_;
    theta=0;
    orbitspeed = random(0.01,0.03);
  }
  void update(){
    theta+=orbitspeed;
  }
  void display(){
    pushMatrix();
    rotate(theta);
    translate(distance,0);
    stroke(0);
    fill(175);
    ellipse(0,0,diameter,diameter);
    popMatrix();
  }
}
//Source: Daniel Schiffman's book

In this simulation, the distance from the sun, the idle speed,
the size of the planet, etc. are all random. :sob:
What do you think I should do to make these things
like the real solar system?:thinking:
(Is the code I brought in not enough to make the
solar system simulation real?:sweat::sweat:

please format your code posting by pasting it into the

</> code button

of the editor header menu ( context name: Preformatted text )
it looks like
```
type or paste code here
```

also can use the ``` manually above and below your code.

thank you.


you might use different color and size for the planets,

when i play this i found it good to see the orbit / path
of the planets ( by a dotted line… )

next step would be P3D with a 3D view like using library
http://mrfeinberg.com/peasycam/

Modified…Thank you.

1 Like

Only the Orbit speed is random, but i get what you mean…

Well, to make it accurate you don‘t need to do much other than to adapt the actual values of the Solar System to the values to use. You‘ll have to set the variables of individual things in Relation, like (just guessing Numbers) if mars is 2Milion km from the sun and Earth is 3milion km, you‘d want the variables for the distance be 2 * someFactor for mars and 3 * someFactor for earth. And this someFactor variable would probably be different for different values, like 100 for distance, 0.01 for speed and so on. I think you get the point.