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.
- y2: 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:
- Program 1:
functionsetup() {createCanvas(400, 400);}functiondraw() {background(220);fill('lightgreen');// A triangle at (100, 250), (250, 170) and (330, 300)triangle(100, 250, 250, 170, 330, 300);}chevron_rightfilter_noneOutput:

-
Program 2:
functionsetup() {createCanvas(400, 400);}functiondraw() {background(220);fill('red');// A triangle at (200, 100), (100, 200) and (200, 300)triangle(200, 100, 100, 200, 200, 300);}chevron_rightfilter_noneOutput:

Reference: https://p5js.org/reference/#/p5/triangle
Recommended Posts:
- Area of largest triangle that can be inscribed within a rectangle
- Find other two sides and angles of a right angle triangle
- Program to find the Radius of the incircle of the triangle
- Minimum height of a triangle with given base and area
- Area of circle which is inscribed in equilateral triangle
- Area of a square inscribed in a circle which is inscribed in an equilateral triangle
- PHP | cos( ) Function
- PHP | each() Function
- PHP | sin( ) Function
- PHP | abs( ) Function
- PHP | dir() Function
- PHP | ord() Function
- PHP | exp() Function
- CSS | rgb() Function
- CSS | var() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



