Py5Vector.lerp()#

Calculates a vector between two vectors at a specific increment.

Examples#

example picture for lerp()
 1def setup():
 2    v1 = py5.Py5Vector(40, -80)
 3    c1 = py5.color(255, 0, 0)
 4    v2 = py5.Py5Vector(-40, -80)
 5    c2 = py5.color(0, 0, 255)
 6    py5.translate(50, 90)
 7    py5.stroke_weight(4)
 8    py5.stroke(c1)
 9    py5.line(0, 0, v1.x, v1.y)
10    py5.stroke(c2)
11    py5.line(0, 0, v2.x, v2.y)
12    py5.stroke_weight(1)
13    for i in range(1, 10):
14        v = v1.lerp(v2, i / 10)
15        c = py5.lerp_color(c1, c2, i / 10)
16        py5.stroke(c)
17        py5.line(0, 0, v.x, v.y)

Description#

Calculates a vector between two vectors at a specific increment. The two vectors must have the same dimension. The amt parameter is the amount to interpolate between the two values where 0.0 equal to the first point, 0.1 is very near the first point, 0.5 is half-way in between, etc. If the amt parameter is greater than 1.0 or less than 0.0, the interpolated vector will be outside of the range specified by the two vectors.

This method is similar to lerp() and lerp_color(), but for vectors instead of numbers or colors.

Syntax#

lerp(other: Union[Py5Vector, np.ndarray], amt: Union[float, np.ndarray]) -> Union[Py5Vector, np.ndarray[np.floating]]

Parameters#

  • amt: Union[float, np.ndarray] - float between 0.0 and 1.0

  • other: Union[Py5Vector, np.ndarray] - other vector to interpolate between

Updated on February 26, 2022 13:22:44pm UTC