# Function parameters causing unwanted animation

**URL:** https://discourse.processing.org/t/function-parameters-causing-unwanted-animation/29940
**Category:** Beginners
**Created:** [May 7, 2021, 2:10pm UTC](https://discourse.processing.org/t/function-parameters-causing-unwanted-animation/29940 "2021-05-07T14:10:55Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![theta](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/theta/32/13018_2.png) [@theta](https://discourse.processing.org/u/theta)
#### Post date: [May 7, 2021, 2:10pm UTC](https://discourse.processing.org/t/function-parameters-causing-unwanted-animation/29940/1 "2021-05-07T14:10:55Z")

</div>

Hey everyone. I started exploring functions with parameters and can’t for the life of me figure out why the example below is animating.

```auto
Waves w1 = new Waves();

float amp = 100;
float phase = 1;
float freq = 100;
float offset = 0;

void setup() {
  size(600, 600);
  frameRate(60);
}

void draw() {

  background(225, 255, 200);

    if (mousePressed && (mouseButton == LEFT)) {
      phase += 2;
    } else if (mousePressed && (mouseButton == RIGHT)) {
      phase -= 2;
    } 

    if (keyPressed && (key == 'w')) {
      amp += 2;
    } else if (keyPressed && (key == 's')) {
      amp -= 2;
    } 

    if (keyPressed && (key == 'a')) {
      freq += 2;
    } else if (keyPressed && (key == 'd')) {
      freq -= 2;
    } 

    if (keyPressed && (key == 'q')) {
      offset += 2;
    } else if (keyPressed && (key == 'e')) {
      offset -= 2;
    }

  w1.Wave1(amp, phase, freq, offset);
  
}

class Waves {

  float theta = 0.1;
  float thetaInc = TWO_PI/25;

  void Wave1 (float a, float p, float f, float o) {

    for (int i = 0; i < width; i+=1) {
      strokeWeight(10);
      stroke(0);
      point(i, 250+o + ( a*sin(f/100*theta + p/100) ) );

      theta += thetaInc;
    }
    
  }

}

```

What I want is for the wave to animate only when I press a key or mouse button as specified. But when I run it the “phase” aspect of the wave animates (first slow, then fast, then slow). Am I misunderstanding how parameters work? It works exactly the way I want when I draw the wave in directly in draw()

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [May 7, 2021, 2:38pm UTC](https://discourse.processing.org/t/function-parameters-causing-unwanted-animation/29940/2 "2021-05-07T14:38:48Z")

</div>

> [@theta](#):
>
> `theta = 0.1;`

Maybe you want to repeat this at the start of Wave1
