Learn

The last two drawing functions we’ll learn are triangle() and quad(), which are closely related to the line() function in that they take the coordinates of each corner of the shape as arguments. These arguments are used to define the perimeter of the shape.

The triangle() function takes a total of six arguments or three pairs of x and y coordinates.

Diagram of triangle function

The quadrilateral shape function, quad(), needs eight arguments, or four pairs of x and y coordinates for each of its four points.

Diagram of quadrilateral

Instructions

1.

Use the triangle() function to draw a triangle to the p5.js sketch. You can use any coordinates for each of the three vertices of the triangle!

2.

The arguments for the triangle() function represent the vertices of the triangle. Draw a second triangle that shares one vertex with the first triangle you drew.

3.

Next, draw a quadrilateral using the quad() function. You can use any coordinates for each of the four vertices of the quadrilateral!

4.

Draw a second quadrilateral that shares one vertex with the first quadrilateral you drew.

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?