Compartilhar via


rotate method

Rotates the current context coordinates (that is, a transformation matrix).

 

Syntax

object.rotate(angle);

Parameters

  • angle [in]
    Type: number

    The rotation angle, in radians.

Return value

This method does not return a value.

Standards information

Remarks

Rotation is based on the current origin. Rotation is done with radians. To convert from degrees to radians use this algorithm: ([deg] * Math.PI) / 180. Substitute [deg] with the number of degrees you want.

To rotate something on its center (or a specific portion), use translate to set the origin to that point. In the example here, the origin is set to the center of the canvas. The star is drawn using that origin as its center.

When you rotate an image, wait until the image is fully loaded before calculating any rotation. This is because the width and height aren't available until the image has loaded and will result in incorrect calculations.

See also

ICanvasRenderingContext2D::translate