topical media & game development

talk show tell print

graphic-processing-learning-06-example-6-9-example-6-9.pde / pde



  // Learning Processing
  // Daniel Shiffman
  // http://www.learningprocessing.com
  
  // Example 6-9: Simple while loop with interactivity
  
  void setup() {
    size(255,255);
  }
  
  void draw() {
    background(0);
  
    // Start with i as 0
    int i = 0;
  
    // While i is less than the width of the window
    while (i < width) {
      noStroke();
      // The distance between the current rectangle and the mouse is equal to the absolute value of the difference between i and mouseX.
      float distance = abs(mouseX - i); 
      // That distance is used to fill the color of a rectangle at horizontal location i.
      fill(distance);
      rect(i,0,10,height);
      // Increase i by 10
      i += 10;
    }
  }
  


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