Minor problem with scale.

edited October 2013 in Questions about Code

Hi there, I am fairly new to coding and am trying to create a simple animation. I have a rectangle slowly getting larger but everything coded below that rectangle also gets larger.

float a = 1.0;  


void setup()
{
  size(500, 500);
  frameRate(25);
  smooth(); 
  rectMode(CENTER); 
  ellipseMode(CENTER);

} 


void draw() 

{ 

  background(0);

  a = a + 0.01;

  translate(width/2, height/2); 
  fill(0,255,0);
  scale(a);
  rect(0,0,200,200);



  fill(255,0,0);
  ellipse(0,0,100,100);

}

I think it is just a simple problem with my draw structure but basically I don't want the ellipse to take on any of the rectangles properties, in this case scale. Thanks for your help.

Answers

  • edited October 2013

    Just use pushMatrix() to save a transformation. Then popMatrix() to return to its previous form! :bz
    Or even resetMatrix() to get default transformation back! =:)

    // forum.processing.org/two/discussion/623/minor-problem-with-scale-
    
    final static short DIM = 100;
    final static float INITIAL = .5;
    
    float a = INITIAL;
    
    void setup() {
      size(500, 500);
    
      frameRate(60);
      smooth();
    
      rectMode(CENTER); 
      ellipseMode(CENTER);
    } 
    
    void draw() { 
      clear();
      translate(width>>1, height>>1);
    
      pushMatrix();
    
      scale(a += .01);
      if (a > 4.9)  a = INITIAL;
    
      fill(#00FF00);
      rect(0, 0, DIM, DIM);
    
      popMatrix();
    
      fill(#FF0000);
      ellipse(0, 0, DIM, DIM);
    };
    
Sign In or Register to comment.