Rectangle
Description
The rect()
function draws a rectangle on the canvas. The rectangle is drawn centered at the specified (x,y) coordinates.
Syntax
// Using positional parameters
rect(x, y, width, height)
// Using named parameters
rect(x: Float, y: Float, width: Float, height: Float)
Parameters
x
The x-coordinate of the rectangle's center
y
The y-coordinate of the rectangle's center
width
The width of the rectangle
height
The height of the rectangle
Example
// Draw a rectangle at (100, 100) with width 200 and height 150
rect(100, 100, 200, 150)
// Draw a square using named parameters
rect(x: 300, y: 300, width: 100, height: 100)
Notes
- The rectangle is drawn centered at the specified (x,y) coordinates
- The stroke width is set to 3 by default
- The fill and stroke colors can be customized using the current fill and stroke settings