rect()
Rectangle - Draws a rectangle with the given inputs
Last updated
Rectangle - Draws a rectangle with the given inputs
Last updated
Input | Description |
---|---|
x | x co-ordinate of the bottom left corner |
y | y co-ordinate of the bottom left corner |
width | width of the rectangle (length in x direction) |
height | height of the rectangle (length in y direction) |
Input | Description |
---|---|
x | x co-ordinate of the bottom left corner |
y | y co-ordinate of the bottom left corner |
width | width of the rectangle (length in x direction) |
height | height of the rectangle (length in y direction) |
bottomleft | radius of circle of curvature for the bottom left corner |
bottomright | radius of circle of curvature for the bottom right corner |
topright | radius of circle of curvature for the top right corner |
topleft | radius of circle of curvature for the top left corner |
rect() draws a rectangle on the canvas, using the inputs to determine the position and dimension of the shape. The corners can be given a curvature in order to draw a 'rounded rectangle', but the base and height of the rectangle must always be parallel to the x-axis and y-axis respectively - this can only be changed separately with a rotation.
By default, the x and y inputs refer to the bottom left corner of the rectangle.
This can be changed using rectMode()
, with an input of CORNER, CORNERS, RADIUS or CENTER.
This is the default mode. The code:
will use (x,y) as the bottom left corner coordinates and width and height as the dimensions.
This mode is for specifying the coordinates of opposite corners. The code:
will use (x1,y1) as the bottom left corner coordinates and (x2,y2) as the top right (diagonally opposite) corner coordinates.
This mode is for specifying the center of the rectangle together with the width and height. The code:
will use (x,y) as the center coordinates and width and height as the dimensions.
This mode is for specifying the center of the rectangle together with half the width and half the height. The code:
will use (x,y) as the center coordinates and wRadius * 2 and hRadius * 2 as the dimensions.
Find these documents helpful? Let the people who made them help your child learn to code at Strivemath!
We'd love to hear your Feedback/Comments here.