Help with X coordinate that will switch back and forth?

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!!

1 Like

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

2 Likes

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.