Processing Day 5: Variables Part 1

Today I learned about variables in my tutorial. According to Daniel Shiffman’s tutorial about object-oriented programming on, variables are properties of an object. There are many different kinds of variables that you can create:

int = integer

float = decimal number

boolean = true/false

char = single character

byte = used with communication ports/Arduino

color = a color variable

Here is the code from the tutorial I’ve been doing that includes information about these variables:

// video on variables

//int (integer) variable - whole number
//32 bit... plus or minus 2 billion

//declare the variable
int x; //declared x

x=10; //initialized x

println("x=" +x );

//float variable stands for floating point, has decimal places
float e = 2.71828;
println("e=" +e );

//boolean variable for true/false
boolean switchVar = true;
println("switchVar=" +switchVar );
switchVar = !switchVar; //! means this is not that
println("switchVar=" +switchVar );

//Char variable (char means a single character)
char charVar = 'V';
println("charVar=" + charVar );

//byte variable (goes down to -120 and up to 120...usually used in communication with serial ports
//generally used with Arduino
byte dozen = 12;
println("The byte variable \"dozen\" is equal to: " + dozen ); // \means I'm done with my string, I don't want these quotes to print

// color variable
color cherryBlossomPink = #FFB7C5;

This code doesn’t produce any sketches except for a pink background as a result of the last variable listed.


Here also is a screenshot that displays variable scope; in other words you can have global variables which apply to all code, or local variables which apply only to one block of code. The instructor also uses the command <pre>println</pre> which you can see at the bottom of this screenshot.


The result of this sketch? Nothing but a dark gray background.