topical media & game development

talk show tell print

graphic-processing-learning-05-example-5-6-example-5-6.pde / pde



  // Learning Processing
  // Daniel Shiffman
  // http://www.learningprocessing.com
  
  // Example 5-6: Bouncing Ball
  int x = 0;
  int speed = 1;
  
  void setup() {
    size(200,200);
    smooth();
  }
  
  void draw() {
    background(255);
  
    // Add the current speed to the x location.
    x = x + speed;
  
    // Remember, || means "or."
    if ((x > width) || (x < 0)) {
      // If the object reaches either edge, multiply speed by -1 to turn it around.
      speed = speed * -1;
    }
  
    // Display circle at x location
    stroke(0);
    fill(175);
    ellipse(x,100,32,32);
  }
  
  


(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.