Variables are placeholders for information – much like when you use letters in algebra to represent a value. In fact, Python variables look and behave similarly.
Begin a new sketch and then save it as “variables”. To keep things simple, we’ll print to the Console area. Add the following code:
height are system variables that store the dimensions of the display window. However, you are not limited to system variables. When declaring your own variables, you assign a value using an
= sign (assignment operator). Try this out with a new variable named “x”:
You may name your variables whatever you wish, provided the name: contains only alpha-numeric and underscore characters; does not begin with a number; and does not clash with a reserved Python keyword or variable (like
width). For example:
Whether you should name a variable using camelCase, underscores, or some other convention is a matter of style (and vociferous debate). However, it’s good to decide upon and stick to a naming convention, as you’ll make extensive use of variables in Processing. Add three more variables to your script, using them as arguments in a