Reference rectMode()

rectMode()

Changes where rectangles and squares are drawn.

By default, the first two parameters of rect() and square(), are the x- and y-coordinates of the shape's upper left corner. The next parameters set the shape's width and height. This is the same as calling rectMode(CORNER).

rectMode(CORNERS) also uses the first two parameters as the location of one of the corners. The next parameters are the location of the opposite corner. This mode only works for rect().

rectMode(CENTER) uses the first two parameters as the x- and y-coordinates of the shape's center. The next parameters are its width and height.

rectMode(RADIUS) also uses the first two parameters as the x- and y-coordinates of the shape's center. The next parameters are half of the shape's width and height.

The argument passed to rectMode() must be written in ALL CAPS because the constants CENTER, RADIUS, CORNER, and CORNERS are defined this way. JavaScript is a case-sensitive language.

Examples

Syntax

rectMode(mode)

Parameters

mode

either CORNER, CORNERS, CENTER, or RADIUS

Notice any errors or typos? Please let us know. Please feel free to edit src/core/shape/attributes.js and open a pull request!

Related References