O'Reilly logo

Getting Started with Processing by Ben Fry, Casey Reas

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 10. Arrays

We've introduced new programming ideas in each chapter (variables, functions, objects) and now we've come to the last step—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. This makes the code shorter, easier to read, and more convenient to update.

To see what we mean, refer to Example 7-3: Move a Shape. This code works fine if we're moving around only one shape, but what if we want to have two? We need to make a new x variable and update it within draw():

image with no caption
float x1 = 20;

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