sq()#

Squares a number (multiplies a number by itself).

Examples#

example picture for sq()
1def setup():
2    py5.no_stroke()
3    a = py5.sq(1)   # Sets 'a' to 1
4    b = py5.sq(-5)  # Sets 'b' to 25
5    c = py5.sq(9)   # Sets 'c' to 81
6    py5.rect(0, 25, a, 10)
7    py5.rect(0, 45, b, 10)
8    py5.rect(0, 65, c, 10)

Description#

Squares a number (multiplies a number by itself). The result is always a positive number, as multiplying two negative numbers always yields a positive result. For example, -1 * -1 = 1.

Syntax#

sq(value: Union[float, npt.NDArray]) -> Union[float, npt.NDArray]

Parameters#

  • value: Union[float, npt.NDArray] - number to square

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