Py5Vector.set_mag()#

Set the vector’s magnitude.

Examples#

1v1 = py5.Py5Vector(3, 4)
2
3print("magnitude =", v1.mag)
4# magnitude = 5.0
5
6v1.set_mag(1)
7
8print("magnitude =", v1.mag)
9# magnitude = 1.0

Description#

Set the vector’s magnitude. Setting this to a non-negative number will adjust the vector’s magnitude to that value. Negative values will result in an error.

Syntax#

set_mag(mag: float) -> Py5Vector

Parameters#

  • mag: float - vector magnitude

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