# Reversing the draw()/code?

**URL:** <https://discourse.processing.org/t/reversing-the-draw-code/5172>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 4, 2018, 3:44am UTC](https://discourse.processing.org/t/reversing-the-draw-code/5172 "2018-11-04T03:44:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ReDeagle](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@ReDeagle](https://discourse.processing.org/u/ReDeagle)\
**Post date:** [November 4, 2018, 3:44am UTC](https://discourse.processing.org/t/reversing-the-draw-code/5172/1 "2018-11-04T03:44:57Z")

</div>

Hey everyone, I have a project for school where parts of an object come flying in from different parts of a screen into the center to form a car. We aren’t allowed to use if statements either. I know how to code it so the parts go flying out, but is there any way to reverse my code or the draw function to make it so that the parts come flying in?

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 4, 2018, 4:22am UTC](https://discourse.processing.org/t/reversing-the-draw-code/5172/2 "2018-11-04T04:22:39Z")

</div>

It would help a lot if we could see the code you have until now, to understand what to reverse 😅. But for actually reversing draw, there is no thing like that. As for the code, you could probably just reverse some numbers and it should do pretty much that, depending on how your code looks/works.

---

<div class="post-metadata">

**Author:** ![ReDeagle](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@ReDeagle](https://discourse.processing.org/u/ReDeagle)\
**Post date:** [November 4, 2018, 6:20pm UTC](https://discourse.processing.org/t/reversing-the-draw-code/5172/3 "2018-11-04T18:20:00Z")

</div>

Thanks! just wanted to clarify if such a thing existed.

---

<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:** [November 12, 2018, 7:22pm UTC](https://discourse.processing.org/t/reversing-the-draw-code/5172/4 "2018-11-12T19:22:02Z")

</div>

> [@ReDeagle](#):
>
> We aren’t allowed to use if statements either.

This is… strange. Can you share more details from the actual assignment?

> [@ReDeagle](#):
>
> I know how to code it so the parts go flying out, but is there any way to reverse my code or the draw function to make it so that the parts come flying in?

Use lerp (or map):

- [lerp() / Reference / Processing.org](https://processing.org/reference/lerp_.html)
- [map() / Reference / Processing.org](https://processing.org/reference/map_.html)

Given a progress level a, then you find a position x for the flying part. Then you can input a stream of progress 0.1, 0.2, 0.3 … 0.9, 1.0 and the part will fly out. Or, you can input a stream of progress 1.0, 0.9, 0.8 … 0.1, 0.0 and the part will fly in.
