// Learning Processing // Daniel Shiffman // http://www.learningprocessing.com // Example 14-18: Object-oriented solar system class Planet { // Each planet object keeps track of its own angle of rotation. float theta; // Rotation around sun float diameter; // Size of planet float distance; // Distance from sun float orbitspeed; // Orbit speed // Set our control vars int earthYearLength = 365; int earthDiameter = 12756; Planet(float distance_, int diameter_, float yearLength_) { distance = distance_; theta = random(0,TWO_PI); // Set the orbit to random so they don't all start in a line diameter = calculateDiameter(diameter_, earthDiameter); orbitspeed = calculateOrbitSpeed(yearLength_); sphereDetail(8); // Knock level of detail down so we run tings faster. } void update() { // Increment the angle to rotate theta += orbitspeed; } void display() { noStroke(); // Before rotation and translation, the state of the matrix is saved with pushMatrix(). pushMatrix(); // Rotate orbit rotate(theta); // translate out distance translate(distance,0); fill(100); sphere(diameter); // Once the planet is drawn, the matrix is restored with popMatrix() so that the next planet is not affected. popMatrix(); } float calculateOrbitSpeed(float yearLength){ // fuck about so the orbitspeed is something like normal return yearLength*0.005; } float calculateDiameter(float diameter, int control){ // add 3 so we can actually see the bloooomin results return (diameter/control)+2; } }