Rotates the coordinate system.
By default, the positive x-axis points to the right and the positive y-axis points downward. The rotate() function changes this orientation by rotating the coordinate system about the origin. Everything drawn after rotate() is called will appear to be rotated.
The first parameter, angle, is the amount to rotate. For example, calling rotate(1) rotates the coordinate system clockwise 1 radian which is nearly 57˚. rotate() interprets angle values using the current angleMode().
The second parameter, axis, is optional. It's used to orient 3D rotations in WebGL mode. If a p5.Vector is passed, as in rotate(QUARTER_PI, myVector), then the coordinate system will rotate QUARTER_PI radians about myVector. If an array of vector components is passed, as in rotate(QUARTER_PI, [1, 0, 0]), then the coordinate system will rotate QUARTER_PI radians about a vector with the components [1, 0, 0].
By default, transformations accumulate. For example, calling rotate(1) twice has the same effect as calling rotate(2) once. The push() and pop() functions can be used to isolate transformations within distinct drawing groups.
Note: Transformations are reset at the beginning of the draw loop. Calling rotate(1) inside the draw() function won't cause shapes to spin.
rotate() can also be used in shaders with p5.strands. Inside a shader callback, it takes a transform created with transform2D() or transform3D() as its first parameter, as in rotate(myTransform, PI / 4). Instead of turning the coordinate system, it returns a new transform with the turn added on and leaves the one passed in untouched, so the result has to be assigned back. A 2D transform turns within the plane and a 3D transform turns about the z-axis. Angles are always in radians inside a shader. The finished transform is applied to a position with transformPoint(). See its reference for a more in-depth explanation of how that works. The following example uses rotate() to spin a box.
Examples
Syntax
rotate(angle, [axis])
rotate(transform, angle)