p5.js quad() Function
Last Updated :
11 Aug, 2023
The quad() function is an inbuilt function in p5.js which is used to draw a quadrilateral. A quadrilateral is a four-sided polygon. It function creates a shape similar to rectangle, but the angles between two edges are not constrained to 90 degrees.
Syntax:
quad(x1, y1, x2, y2, x3, y3, x4, y4)
or
quad(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
Parameters: This function accepts twelve parameters as mentioned above and described below:
- x1: This parameter takes the x-coordinate of the first point.
- y1: This parameter takes the y-coordinate of the first point.
- z1: This parameter takes the z-coordinate of the first point.
- x2: This parameter takes the x-coordinate of the second point.
- y2: This parameter takes the y-coordinate of the second point.
- z2: This parameter takes the z-coordinate of the second point.
- x3: This parameter takes the x-coordinate of the third point.
- y3: This parameter takes the y-coordinate of the third point.
- z3: This parameter takes the z-coordinate of the third point.
- x4: This parameter takes the z-coordinate of the fourth point.
- y4: This parameter takes the z-coordinate of the fourth point.
- z4: This parameter takes the z-coordinate of the fourth point.
Below programs illustrates the quad() function in P5.js:
Example 1: This example uses quad() function to create a polygon without using z-coordinate.
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
noStroke();
fill( 'green' );
quad(38, 31, 300, 20, 100, 63, 130, 250);
}
|
Output:
Example 2: This example uses quad() function to create polygon with z-coordinate.
function setup() {
createCanvas(400, 400);
}
function draw() {
background(99);
noStroke();
fill( 'pink' );
quad(38, 131, 100, 320, 100, 63,
130, 150, 134, 155, 66, 88);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/quad
Share your thoughts in the comments
Please Login to comment...