# Mouse Clicked function and storing variables

**URL:** <https://discourse.processing.org/t/mouse-clicked-function-and-storing-variables/11823>\
**Category:** Coding Questions\
**Created:** [June 4, 2019, 3:38am UTC](https://discourse.processing.org/t/mouse-clicked-function-and-storing-variables/11823 "2019-06-04T03:38:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pbchocochipcheerios](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@Pbchocochipcheerios](https://discourse.processing.org/u/Pbchocochipcheerios)\
**Post date:** [June 4, 2019, 3:38am UTC](https://discourse.processing.org/t/mouse-clicked-function-and-storing-variables/11823/1 "2019-06-04T03:38:29Z")

</div>

Hello! I am new to processing and was hoping someone can help.

I am drew an object and need it to glide from one mouse click location to another.

I used the mouseClicked function and stored the X and Y of when the mouse is clicked like this:

newX = mouseX  
newY = mouseY

But is there is a way to store the next set of mouse clicks so I can calculate the distance between them for the glide? And of course when I click again after the initial two clicks, I need the second click variables to be stored with the third click variables.

Thanks for all your help. I have been trying to figure this out for 2 days now and my head might explode soon!!

---

<div class="post-metadata">

**Author:** ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)\
**Post date:** [June 4, 2019, 5:43am UTC](https://discourse.processing.org/t/mouse-clicked-function-and-storing-variables/11823/2 "2019-06-04T05:43:58Z")

</div>

Here is a few things you might find helpful:

- [Easing Example](https://processing.org/examples/easing.html)
- ArrayList - [Documentation](https://processing.org/reference/ArrayList.html) - [Video Tutorial by Dan Shiffman](https://www.youtube.com/watch?v=HnSJZ4qTcwY&list=PLRqwX-V7Uu6Z9hI4mSgx2FlE5w8zvjmEy&index=2)
- PVector - [Documentation](https://processing.org/reference/PVector.html) - [Video Tutorial by Dan Shiffman](https://www.youtube.com/watch?v=7nTLzLf7jUg&list=PLRqwX-V7Uu6ZwSmtE13iJBcoI-r4y7iEc&index=2)

Here’s what I would try:

Create an arraylist and in setup add a random (or `mouseX` and `mouseY`) location to it.

Use the mouse clicked function add a location to the end of an arraylist.

Then in draw you have the object move towards the first thing in the arraylist. And If the object is within a certain distance (look into [`dist()`](https://processing.org/reference/dist_.html)) and the `arraylist.size()` is greater than 1 remove the first element in the arraylist.

Hope that make sense and is helpful.
