When I run the code above, we get the "hello world" text we specified to the println (print line) function. The println is a handy tool to debug or troubleshoot problems or to check the value of elements in your code, for instance when we start using variables next you can use println to check the value of your variable throughout your code by using println.
So lets next look to use a variable, which is a reference to a value you can set and manipulate throughout your code to achieve animations or store data.
For now, we'll just use a variable to store the value "hello world" and then print it again. Variables can be called anything you want so long as they don't conflict with something processing uses (like setup or println) and that it doesn't contain spaces. Also, as general practice variables don't contain numbers, but underscores "_" or "camelCaps" are commonly used to make reading them easier. Lets create one called
ourNewVariable capitalizing each word for clarity.
01
02
03
04
05
06
07
08
09
10
String ourNewVariable;
void setup(){
size(500,500);
background(0,0,0);
ourNewVariable = "hello world";
}
void setup(){
println(ourNewVariable);
}
In Processing each variable has a type, which specifies what kind of value it holds or can hold. So when we create or variable "ourNewVariable" we know we want it to hold a piece of text, and the corresponding type for text is known as a string. Think of it as a line of text is a group of letters or characters
strung together, therefore we call them
strings. Some examples types we'll use are
int for integers
float for floating point or decimals and
boolean for true or false values.
Also, lets use a new function called
draw, which like setup is known by processing (and is therefore highlighted orange). Processing looks for our draw function, and if it finds one calls it repeatedly at a set rate -- by default 60 frames a second. Processing works like video or other types of animated media by using
frames to depict movement.
Motion Perception is an interesting
and still somewhat unknown process.