# Help with X coordinate that will switch back and forth?

**URL:** <https://discourse.processing.org/t/help-with-x-coordinate-that-will-switch-back-and-forth/11843>\
**Category:** Coding Questions\
**Created:** [June 4, 2019, 6:32pm UTC](https://discourse.processing.org/t/help-with-x-coordinate-that-will-switch-back-and-forth/11843 "2019-06-04T18:32:15Z")\
**Posts on this page:** 3\
**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, 6:32pm UTC](https://discourse.processing.org/t/help-with-x-coordinate-that-will-switch-back-and-forth/11843/1 "2019-06-04T18:32:15Z")

</div>

I want to animate a triangle by changing the x2 point to match x1 so that it becomes a line. I want it to look like it is a triangle switching from triangle to line, triangle to line, etc. Does anyone know how I can do this?

Thank you!!

---

<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:** [June 4, 2019, 6:50pm UTC](https://discourse.processing.org/t/help-with-x-coordinate-that-will-switch-back-and-forth/11843/2 "2019-06-04T18:50:40Z")

</div>

You can add a value to x2:

x2= x2 + x2add;

Now when x2 \<= x1 say x2add = x2add\*-1;

Say the same when x2\>=500 or so, so x2 bounces on both sides

---

<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:** [June 6, 2019, 5:55am UTC](https://discourse.processing.org/t/help-with-x-coordinate-that-will-switch-back-and-forth/11843/3 "2019-06-06T05:55:51Z")

</div>

One approach:

Given 3 random points

1. pick two
2. draw a line between them.
3. find the midpoint.
4. move your 3rd point toward that midpoint. You can use PVector.lerp to animate a transition between two known points.
5. when the 3rd point is on the midpoint, the 3 points will form a line.
