# Time-base Pattern Help

**URL:** <https://discourse.processing.org/t/time-base-pattern-help/4398>\
**Category:** Coding Questions\
**Created:** [October 12, 2018, 5:05pm UTC](https://discourse.processing.org/t/time-base-pattern-help/4398 "2018-10-12T17:05:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ehasti21](https://avatars.discourse-cdn.com/v4/letter/e/e36b37/32.png) [@ehasti21](https://discourse.processing.org/u/ehasti21)\
**Post date:** [October 12, 2018, 5:05pm UTC](https://discourse.processing.org/t/time-base-pattern-help/4398/1 "2018-10-12T17:05:19Z")

</div>

Hello all, we are currently working on a time-based pattern project for class but i’ve manage to hit a wall working on my code. I am new to working in the program so i’m a tad confused.

1. I would like to make it to where my animation starts at the initial press of the mouse then the ellipse changes/transitions color if the mouse button is held.
2. I would like to have more than just one ellipse traveling on my sin wave!

I greatly appreciate any help or explanations given!

```auto
float rad;
float xOrigin, yOrigin;
float yPos;
boolean toLeft;

void setup() {
  size(500, 500);
  rad = 50;
  yOrigin = height/2;
  toLeft = false;
}

void draw() {
  background(0);  
  noStroke(); 

  yPos =cos(frameCount * 0.15) * rad;
  ellipse (xOrigin, yOrigin + yPos, 20, 20);
  
  if (toLeft==false) {
    xOrigin = xOrigin + 5;
    if (xOrigin > 500) {  
      toLeft = true;
    }
  }

  else {
    xOrigin = xOrigin - 5; 
    if (xOrigin < 0) {
      toLeft = false;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 24, 2018, 6:47pm UTC](https://discourse.processing.org/t/time-base-pattern-help/4398/2 "2018-10-24T18:47:06Z")

</div>

> [@ehasti21](#):
>
> I would like to make it to where my animation starts at the initial press of the mouse then the ellipse changes/transitions color if the mouse button is held.

One way is to use mousePressed() and loop() / noLoop();

See the noLoop example sketch:

> **[noLoop() / Reference](https://processing.org/reference/noLoop_.html)**
>
> Stops Processing from continuously executing the code within draw(). If loop() is called, the code in draw() begin to run continuously again. If using noLoop() in setup(…

It sounds like you want the opposite – set noLoop by default, set loop when pressed, and set noLoop again when released.
