topical media & game development

talk show tell print

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



  // Learning Processing
  // Daniel Shiffman
  // http://www.learningprocessing.com
  
  // Example 14-3: A rectangle moving along the z-axis
  
  // A variable for the Z (depth) coordinate
  float z = 0;
  
  void setup() {
    // When using (x,y,z) coordinates, we must tell Processing we want a 3D sketch. 
    // This is done by adding a third argument, P3D (or OPENGL), to the size() function. 
    size(200,200,P3D); 
  }
  
  void draw() {
    background(255);
    stroke(0);
    fill(175);
    
    // Translate to a point before displaying a shape there
    translate(width/2,height/2,z);
    rectMode(CENTER);
    rect(0,0,8,8); 
    
    // Increment z (i.e. move the shape toward the viewer)
    z++ ;
    
    // Restart rectangle
    if (z > 200) {
      z = 0;
    }
    
    
    
  }
  


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