// // Code tennis, Messrs. J. Pett & B. Harvey // // Built from... // Learning Processing // Daniel Shiffman // http://www.learningprocessing.com // Example 14-18: Object-oriented solar system import processing.opengl.*; int numPlanets = 9; //int numLines = 100; // An array of 9 planet objects Planet[] planets = new Planet[numPlanets]; //Lines[] lines = new Lines[numLines]; // Set up the data that the planets will be formed with float[] yearLength = new float[numPlanets]; int[] diameter = new int[numPlanets]; // An array of 8 orbit lines (this is to hold the diameters) float[] orbitLines = new float[numPlanets]; void setup() { size(600,400, OPENGL); smooth(); // These are the actual orbit times in days, but // the difference is so friggin massive that we // are better off making them up to be something // like useable, and it's as reasonabley relative // as you can be when dealing with cosmological // scales. /* yearLength[0] = 88; yearLength[1] = 225; yearLength[2] = 365; yearLength[3] = 687; yearLength[4] = 4331; yearLength[5] = 10759; yearLength[6] = 30687; yearLength[7] = 60190; yearLength[8] = 90553; */ yearLength[0] = 9; yearLength[1] = 8; yearLength[2] = 7; yearLength[3] = 6; yearLength[4] = 5; yearLength[5] = 4; yearLength[6] = 3; yearLength[7] = 2; yearLength[8] = 1; // Diameters of planets in km diameter[0] = 4880; diameter[1] = 12104; diameter[2] = 12756; diameter[3] = 6788; diameter[4] = 142740; diameter[5] = 120034; diameter[6] = 51152; diameter[7] = 49620; diameter[8] = 2296; // The planet objects are initialized using the counter variable for (int i = 0; i < planets.length; i++ ) { planets[i] = new Planet(40 + i*20,diameter[i],yearLength[i]); orbitLines[i] = 40 + i*20; } /* for (int i = 0; i < lines.length; i++ ) { lines[i] = new Lines(); } */ } void draw() { background(200); // Drawing the Sun pushMatrix(); translate(300,160,-10); // Centre the shitz rotateX(1); // Rotate around the X axis to give us some depth like. noStroke(); fill(255); sphere(20); // Draw the sun stroke(255,0,0); // Set the orbit colour lines noFill(); // Draw the orbit lines for (int i = 0; i < orbitLines.length; i++ ) { ellipse(0,0,orbitLines[i]*2,orbitLines[i]*2); } // Drawing all Planets for (int i = 0; i < planets.length; i++ ) { planets[i].update(); planets[i].display(); } /* for (int i = 0; i < lines.length; i++ ) { lines[i].update(); lines[i].display(); } */ popMatrix(); }