Lesson 5.2

Function Parameters and Arguments

Watch: Function Parameters and Arguments- p5.js tutorial

Video for 5.2:

By defining our own functions with parameters, we can make many variations of a type of drawing by changing the arguments used to call the function. For example, the ellipse function included with p5.js was defined with 4 parameters which allow us to draw different ellipses depending on the arguments we pass to it when we call the function.

Exercise 5.2a: Define a function named ring that has 4 parameters; x,y,outerDiameter, innerDiameter. It would be called with ring(x,y,outerDiameter, innerDiameter). Have it generate a new ring every time the page is refreshed - keep it centered on the canvas. Below are two examples of rings.

Exercise 5.2b: Define a function named pipe that has 3 parameters; a height, h, an outer diameter, outerDiameter, and an inner diameter, innerDiameter. It would be called with pipe(h,outerDiameter,innerDiameter). Always have it centered at (200,200). Have it generate a new pipe every time the page is refreshed. Below are two examples of pipes.