topical media & game development

talk show tell print

graphic-processing-learning-14-example-14-18-example-14-18.pde / pde



  // Learning Processing
  // Daniel Shiffman
  // http://www.learningprocessing.com
  
  // Example 14-18: Object-oriented solar system
  
  // An array of 8 planet objects
  Planet[] planets = new Planet[8];
  
  void setup() {
    size(200,200);
    smooth();
    
    // The planet objects are initialized using the counter variable
    for (int i = 0; i < planets.length; i++ ) {
      planets[i] = new Planet(20 + i*10,i + 8);
    }
  }
  
  void draw() {
    background(255);
    
    // Drawing the Sun
    pushMatrix();
    translate(width/2,height/2);
    stroke(0);
    fill(255);
    ellipse(0,0,20,20);
    
    // Drawing all Planets
    for (int i = 0; i < planets.length; i++ ) {
      planets[i].update();
      planets[i].display();
    }
    popMatrix();
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.