p5.js triangle() Function
The triangle() function is an inbuilt function in p5.js which is used to draw a triangle in a plane. This function accepts three vertices of triangle.
Syntax:
triangle(x1, y1, x2, y2, x3, y3)
Parameters: This function accepts six parameters as mentioned above and described below:
- x1: This parameter accept the x-coordinate of first point.
- y1: This parameter accept the y-coordinate of first point.
- x2: This parameter accept the x-coordinate of second point.
- y2: This parameter accept the y-coordinate of second point.
- x3: This parameter accept the x-coordinate of third point.
- y3: This parameter accept the y-coordinate of third point.
Below programs illustrates the triangle() function in p5.js:
javascript
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
fill( 'lightgreen' );
triangle(100, 250, 250, 170, 330, 300);
}
|
javascript
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
fill( 'red' );
triangle(200, 100, 100, 200, 200, 300);
}
|
Reference: https://p5js.org/reference/#/p5/triangle
Last Updated :
11 Aug, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...