# Add mouseClicked moving to bicycle

**URL:** https://discourse.processing.org/t/add-mouseclicked-moving-to-bicycle/4177
**Category:** Coding Questions
**Created:** [October 6, 2018, 4:04am UTC](https://discourse.processing.org/t/add-mouseclicked-moving-to-bicycle/4177 "2018-10-06T04:04:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![BigZi](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@BigZi](https://discourse.processing.org/u/BigZi)
#### Post date: [October 6, 2018, 4:04am UTC](https://discourse.processing.org/t/add-mouseclicked-moving-to-bicycle/4177/1 "2018-10-06T04:04:22Z")

</div>

So i drew a bicycle with 2 ellipse and a few lines in my void body(). I also added a code whereby the bike is reduced size on the left and big on the right. All my code line were written using constant. I used mouseX and mouseY to asign the bike’s location on the sketch and it follows it around. So far it works just fine. But now i want to add a mouseClicked function but i have no clue how. I want the bike to move where i click it on the canvas and stay there until i click somewhere else where it will slowly move towards the new point. I also wanted to keep the code about the size where its small on left, big on right. Can anyone help me? please.

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [October 6, 2018, 4:23am UTC](https://discourse.processing.org/t/add-mouseclicked-moving-to-bicycle/4177/2 "2018-10-06T04:23:52Z")

</div>

Here is some example code demonstrating the variables and functions required to achieve that effect easily:

```java
float current_x, current_y;
float target_x, target_y;
float lerp_amt = 0;
float d_lerp_amt = 0.02;

void setup() {
  size(400, 400);
  target_x = width / 2;
  target_y = height/2;
  current_x = target_x;
  current_y = target_y;
  rectMode(CENTER);
}

void draw() {
  background(0);
  if( lerp_amt > 0){
    lerp_amt-=d_lerp_amt;
  }
  current_x = lerp(target_x, current_x, lerp_amt);
  current_y = lerp(target_y, current_y, lerp_amt);
  pushMatrix();
  translate(current_x, current_y);
  scale( map(current_x, 0, width, 3,0.1) );
  rect(0, 0, 20, 20);
  popMatrix();
}

void mousePressed() {
  target_x = mouseX;
  target_y = mouseY;
  lerp_amt = 1;
}

```

---

<div class="post-metadata">

### Author: ![BigZi](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@BigZi](https://discourse.processing.org/u/BigZi)
#### Post date: [October 7, 2018, 2:48am UTC](https://discourse.processing.org/t/add-mouseclicked-moving-to-bicycle/4177/3 "2018-10-07T02:48:13Z")

</div>

Thanks a lot man. It was really helpful.
