topical media & game development

talk show tell print

graphic-processing-learning-14-example-14-15-Rotater.pde / pde



  // Learning Processing
  // Daniel Shiffman
  // http://www.learningprocessing.com
  
  // Example 14-15: Rotating many things using objects
  
  // A Rotater class
  class Rotater {
    
    float x,y;   // x,y location
    float theta; // angle of rotation
    float speed; // speed of rotation
    float w;     // size of rectangle
    
    Rotater(float tempX, float tempY, float tempSpeed, float tempW) {
      x = tempX;
      y = tempY;
      // Angle is always initialized to 0
      theta = 0; 
      speed = tempSpeed;
      w = tempW;
    }
    
    // Increment angle
    void spin() {
      theta += speed;
    }
    
    // Display rectangle
    void display() {
      rectMode(CENTER);
      stroke(0);
      fill(0,100);
      // pushMatrix() and popMatrix() are called inside the class' display() method. 
      // This way, every Rotater object is rendered with its own independent translation and rotation!
      pushMatrix(); 
      translate(x,y);
      rotate(theta);
      rect(0,0,w,w);
      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.