Example
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 4-3: Varying variables

// Declare and initialize two integer variables at the top of the code.
int circleX = 0;
int circleY = 100;

void setup() {
  size(200,200);
  smooth();
}

void draw() {
  background(255);
  stroke(0);
  fill(175);
  // Use the variables to specify the location of an ellipse.
  ellipse(circleX,circleY,50,50);
  
  // An assignment operation that increments the value of circleX by 1.
  circleX = circleX + 1;
}

  • http://blog.gabrielmathews.com Gabe

    so what is the solution to varying the speed at which the circle grows? I wound up using the abs() call as it was in the previous chapter.

  • admin

    In this case, you just want to define a variable for the size of the circle, instead of hardcoding the number 50 in, i.e.

    int circleW = 100;
    int circleH = 100;
    

    Then you use those variables when drawing the circle.

      ellipse(circleX,circleY,circleW,circleH);
    

    And then adjust the values however you like!

      circleW = circleW + 1;  // Growing
      circleH = circleH - 1;  // Shrinking
    
  • http://Blog.gabrielmathews.com Gabe

    Thanks. I’m sure I’ll have more questions in the hover chapters…:)

  • http://twitter.com/stani101 stani

    here is my code:

    // Declare and initialize two integer variables at the top of the code.float circleSize = 0;float circleX = 100;float circleY = 100;//float speed = 0.0;//float offset = 0.0;void setup() {  size(200,200);  smooth();}void draw() {  background(0);  stroke(255);  fill(175);  // Use the variables to specify the location of an ellipse.  ellipse(circleX,circleY,circleSize,circleSize);  circleSize++;  //speed+=offset;    }

  • http://twitter.com/stani101 stani

    to vary speed:

    // Declare and initialize two integer variables at the top of the code.int circleSize = 0;int circleX = mouseX;int circleY = mouseY;void setup() {  size(200,200);  smooth();}void draw() {  background(0);  stroke(255);  fill(175);  // Use the variables to specify the location of an ellipse.  ellipse(pmouseX,pmouseY,circleSize,circleSize);  circleSize++;     }

  • http://twitter.com/stani101 stani

    // Declare and initialize two integer variables at the top of the code.
    int circleSize = 0;
    int circleX = 100;
    int circleY = 100;

    void setup() {
      size(200,200);
      background(0);
      smooth();
    }

    void draw() {
        //background(0);
    }

    void mouseMoved() {
      //background(0);
      ellipseMode(CENTER);
      stroke(255);
      fill(175);
      // Use the variables to specify the location of an ellipse.
      ellipse(circleX,circleY,circleSize,circleSize);
      circleSize++;
    }