# How to move a object, not in draw()

**URL:** <https://discourse.processing.org/t/how-to-move-a-object-not-in-draw/18761>\
**Category:** Coding Questions\
**Created:** [March 18, 2020, 4:56am UTC](https://discourse.processing.org/t/how-to-move-a-object-not-in-draw/18761 "2020-03-18T04:56:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike2020](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Mike2020](https://discourse.processing.org/u/Mike2020)\
**Post date:** [March 18, 2020, 4:56am UTC](https://discourse.processing.org/t/how-to-move-a-object-not-in-draw/18761/1 "2020-03-18T04:56:09Z")

</div>

Hi folks, how to move a object, not in draw()?  
I make a function ship(), how can I make the ship() move from one point to another point slowly ? Is there any function relate to time, for example ship() can move from point (0, 0) to point(100, 100) druing 5 seconds ?  
Thanks.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [March 18, 2020, 8:00am UTC](https://discourse.processing.org/t/how-to-move-a-object-not-in-draw/18761/2 "2020-03-18T08:00:44Z")

</div>

Welcome to the forum.

Going to have to be more specific, thread() can be used to run things outside draw, but its an asynchronous function.

---

<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:** [March 18, 2020, 9:12am UTC](https://discourse.processing.org/t/how-to-move-a-object-not-in-draw/18761/3 "2020-03-18T09:12:49Z")

</div>

Hello!

Welcome to the forum!

A sketch like this [https://www.processing.org/examples/linear.html](https://www.processing.org/examples/linear.html) can run in draw() but also in ship(), when ship() is called from draw().

When you add only small numbers, the ship moves slowly.

* * *

**Movement with timer**

To have a precise movement during 5 seconds, you have to put some thoughts in.

You could set a timer `int timerStart=millis();`

Then the formula millis()-timerStart gives you the time since the ship started:

`timeSinceStart=millis()-timerStart;`

Then you can calculate the amt value for lerp:

`amt = map(timeSinceStart, 0, 5000, 0,1); // amt is between 0 and 1`

Don’t forget to set amt to 1 once 1 is reached (otherwise it runs on I think and goes beyond 100,100).

then say

```auto
 shipX=lerp(0,100,amt); 
 shipY=lerp(0,100,amt);

```

to get the ship position between 0 and 100 for both x and y.

Regards, Chrisir

---

<div class="post-metadata">

**Author:** ![Mike2020](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Mike2020](https://discourse.processing.org/u/Mike2020)\
**Post date:** [March 18, 2020, 12:56pm UTC](https://discourse.processing.org/t/how-to-move-a-object-not-in-draw/18761/4 "2020-03-18T12:56:08Z")

</div>

Hi sir. very appreciate for your reply, i have never try thread(), it looks a advanced topic to me, but i wll try.

---

<div class="post-metadata">

**Author:** ![Mike2020](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Mike2020](https://discourse.processing.org/u/Mike2020)\
**Post date:** [March 18, 2020, 12:57pm UTC](https://discourse.processing.org/t/how-to-move-a-object-not-in-draw/18761/5 "2020-03-18T12:57:31Z")

</div>

Hi sir, thank you for your so detail help, i will try your idea in my project, thanks for your time.
