Home‎ > ‎Unit 03‎ > ‎


Read Pages 37 - 40 of Getting Started with Processing about Variables and watch the video below. Often we'll want to use the same number over and over again. For example, lets say you want to fill the screen with squares that are 20x20. So, you write the code for 30 or so squares and run the sketch, only to find 20x20 is too small and you want 30x30. Now you have to go in and change every one. If you'd used a variable, you could change one number and re-run the sketch in moments.

Variable Types:
 Type   Range  Notes
 int  +- 2,147,483,647  Whole Numbers only 
 float  +-3.40282347E+38   Decimals 
 long  +-9,223,372,036,854,775,808   Whole Numbers only

You should refer to the Processing Reference for more information on data types. You will use variables of varying data types throughout your programs. There are other types of data Processing programs can use. We'll introduce more as we need them.

Note: Using intfloat or, long declares a variable. You only do this once for each variable. Afterwards you can reassign a variable simply using a equals sign. 

For Example:
int a = 10;  //Declares the variable and sets it equal to 10

a = 30;      //Replaces the 10 with 30

Assignment 3.1 - Re-write the code for your "robot" from assignment 2.3 to include variables. See page 49 in Getting Started with Processing for inspiration.