Reference shearX()

shearX()

Shears the x-axis so that shapes appear skewed.

By default, the x- and y-axes are perpendicular. The shearX() function transforms the coordinate system so that x-coordinates are translated while y-coordinates are fixed.

The first parameter, angle, is the amount to shear. For example, calling shearX(1) transforms all x-coordinates using the formula x = x + y * tan(angle). shearX() interprets angle values using the current angleMode().

By default, transformations accumulate. For example, calling shearX(1) twice has the same effect as calling shearX(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 shearX(1) inside the draw() function won't cause shapes to shear continuously.

shearX() 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 shearX(myTransform, PI / 8). Instead of shearing the coordinate system, it returns a new transform with the shear added on and leaves the one passed in untouched, so the result has to be assigned back. 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 shearX() in a filter shader to shear the canvas.

Examples

Syntax

shearX(angle)
shearX(transform, angle)

Parameters

angle
Number: angle to shear by in the current angleMode().
transform
a transform created with transform2D() or transform3D(), inside a p5.strands shader callback.

Returns

a new transform with the shear applied.

Related References