This reference is for Processing 2.0+. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Class | PVector
Name | ### lerp()
Examples |
    // Non-static (lerp on a specific vector)

    PVector current;
    PVector target;

    void setup() {
      current = new PVector(0.0, 0.0);
      target = new PVector(100.0, 100.0);
      current.lerp(target, 0.5);
      println(current);  // Prints "[ 50.0, 50.0, 0.0 ]"
    }
    // Static (return a new vector)

    PVector start;
    PVector end;
    PVector middle;

    void setup() {
      start = new PVector(0.0, 0.0);
      end = new PVector(100.0, 100.0);
      middle = PVector.lerp(start, end, 0.5);
      println(middle);  // Prints "[ 50.0, 50.0, 0.0 ]"
    }
    // Non-static (lerp on a specific vector)

    PVector v;

    void setup() {
      v = new PVector(0.0, 0.0);
    }

    void draw() {
      v.lerp(mouseX, mouseY, 0.0, 0.1);
      ellipse(v.x, v.y, 20, 20);
    }
Description | Calculates linear interpolation from one vector to another vector. (Just like regular lerp(), but for vectors.) Note that there is one static version of this method, and two non-static versions. The static version, lerp(v1, v2, amt) is given the two vectors to interpolate and returns a new PVector object. The static version is used by referencing the PVector class directly. (See the middle example above.) The non-static versions, lerp(v, amt) and lerp(x, y, z, amt), do not return a new PVector, but transform the values of the PVector on which they are called. These non-static versions function the same way, but the former takes another vector as input, while the latter takes three float values. (See the top and bottom examples above, respectively.)
Syntax |
    .lerp(v, amt)
    .lerp(v1, v2, amt)
    .lerp(x, y, z, amt)
Parameters |
v | PVector: the vector to lerp to
amt | float: The amount of interpolation; some value between 0.0 (old vector) and 1.0 (new vector). 0.1 is very near the new vector. 0.5 is halfway in between.
v1 | PVector: the vector to start from
v2 | PVector: the vector to lerp to
x | float: the x component to lerp to
y | float: the y component to lerp to
z | float: the z component to lerp to
Returns | void or PVector
Related | lerp()

Updated on May 19, 2014 05:30:03pm PDT