Triangle
Description
The triangle()
function draws a triangle on the canvas by connecting three vertices in order (1→2→3→1).
Syntax
// Using positional parameters
triangle(x1, y1, x2, y2, x3, y3)
// Using named parameters
triangle(x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float)
Parameters
x1, y1
The coordinates of the first vertex
x2, y2
The coordinates of the second vertex
x3, y3
The coordinates of the third vertex
Example
// Draw a triangle with vertices at (100,100), (200,100), and (150,200)
triangle(100, 100, 200, 100, 150, 200)
// Draw a triangle using named parameters
triangle(
x1: 300, y1: 300,
x2: 400, y2: 300,
x3: 350, y3: 400
)
Notes
- The vertices are connected in order (1→2→3→1)
- The stroke width is set to 3 by default
- The fill and stroke colors can be customized using the current fill and stroke settings