Chapter 9. Functions

Functions are the basic building blocks for p5.js programs. They have appeared in every example we’ve presented. For instance, we’ve frequently used the createCanvas() function, the line() function, and the fill() function. This chapter shows how to write new functions to extend the capabilities of p5.js beyond its built-in features.

The power of functions is modularity. Functions are independent software units that are used to build more complex programs—like LEGO bricks, where each type of brick serves a specific purpose, and making a complex model requires using the different parts together. As with functions, the true power of these bricks is the ability to build many different forms from the same set of elements. The ...

Get Make: Getting Started with p5.js now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.