rect_mode()#

Modifies the location from which rectangles are drawn by changing the way in which parameters given to rect() are intepreted.

Examples#

example picture for rect_mode()
1def setup():
2    py5.rect_mode(py5.CORNER)  # default rect_mode is CORNER
3    py5.fill(255)  # set fill to white
4    py5.rect(25, 25, 50, 50)  # draw white rect using CORNER mode
5
6    py5.rect_mode(py5.CORNERS)  # set rect_mode to CORNERS
7    py5.fill(100)  # set fill to gray
8    py5.rect(25, 25, 50, 50)  # draw gray rect using CORNERS mode
example picture for rect_mode()
1def setup():
2    py5.rect_mode(py5.RADIUS)  # set rect_mode to RADIUS
3    py5.fill(255)  # set fill to white
4    py5.rect(50, 50, 30, 30)  # draw white rect using RADIUS mode
5
6    py5.rect_mode(py5.CENTER)  # set rect_mode to CENTER
7    py5.fill(100)  # set fill to gray
8    py5.rect(50, 50, 30, 30)  # draw gray rect using CENTER mode

Description#

Modifies the location from which rectangles are drawn by changing the way in which parameters given to rect() are intepreted.

The default mode is rect_mode(CORNER), which interprets the first two parameters of rect() as the upper-left corner of the shape, while the third and fourth parameters are its width and height.

rect_mode(CORNERS) interprets the first two parameters of rect() as the location of one corner, and the third and fourth parameters as the location of the opposite corner.

rect_mode(CENTER) interprets the first two parameters of rect() as the shape’s center point, while the third and fourth parameters are its width and height.

rect_mode(RADIUS) also uses the first two parameters of rect() as the shape’s center point, but uses the third and fourth parameters to specify half of the shapes’s width and height.

The parameter must be written in ALL CAPS because Python is a case-sensitive language.

Underlying Processing method: rectMode

Syntax#

rect_mode(mode: int, /) -> None

Parameters#

  • mode: int - either CORNER, CORNERS, CENTER, or RADIUS

Updated on November 12, 2021 11:30:58am UTC