O'Reilly logo

Make: Getting Started with p5.js by Ben Fry, Casey Reas, Lauren McCarthy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. Arrays

An array is a list of variables that share a common name. Arrays are useful because they make it possible to work with more variables without creating a new name for each one. This makes the code shorter, easier to read, and more convenient to update.

From Variables to Arrays

When a program needs to keep track of one or two things, it’s not necessary to use an array. In fact, adding an array might make the program more complicated than necessary. However, when a program has many elements (for example, a field of stars in a space game or multiple data points in a visualization), arrays make the code easier to write.

Example 11-1: Many Variables

To see what we mean, refer to Example 8-3. This code works fine if we’re moving ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required