O'Reilly logo

Make: Getting Started with Processing, 2nd Edition 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 4. Variables

A variable stores a value in memory so that it can be used later in a program. The variable can be used many times within a single program, and the value is easily changed while the program is running.

First Variables

One of the reasons we use variables is to avoid repeating ourselves in the code. If you are typing the same number more than once, consider using a variable instead so that your code is more general and easier to update.

Example 4-1: Reuse the Same Values

For instance, when you make the y coordinate and diameter for the three circles in this example into variables, the same values are used for each ellipse:

size(480, 120);
int y = 60;
int d = 80;
ellipse(75, y, d, d);    // Left
ellipse(175, y, d, d);   // Middle ...

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