Py5Vector.set_limit()#

Constrain the vector’s magnitude to a specified value.

Examples#

 1def draw():
 2    py5.background(128)
 3    py5.translate(py5.width / 2, py5.height / 2)
 4    v1 = py5.Py5Vector(py5.mouse_x - py5.width / 2, py5.mouse_y - py5.height / 2)
 5
 6    py5.stroke(0)
 7    py5.stroke_weight(5)
 8    py5.line(0, 0, v1.x, v1.y)
 9
10    v1.set_limit(25)
11
12    py5.stroke(255, 0, 0)
13    py5.stroke_weight(2)
14    py5.line(0, 0, v1.x, v1.y)

Description#

Constrain the vector’s magnitude to a specified value. If the vector’s magnitude is already less than or equal to max_mag, this method will have no effect. If the vector’s magnitude is larger, it will be set to max_mag. The max_mag parameter cannot be a negative number.

Syntax#

set_limit(max_mag: float) -> Py5Vector

Parameters#

  • max_mag: float - maximum vector magnitude

Updated on January 16, 2022 16:51:21pm UTC