Processing is a programming language that extends the Java programming language. It has very many nice features for creating programs that use graphics. Before we get to that we will look at some simpler programs that will just display some text.
There are two commands for displaying text. They are println and print. We will look at the difference between the two shortly. Here is an example of using println:
|
This will print |
You can combine several println statements together. Each one will produce one line of output. The following example will produce three lines of output:
|
one line line 2 A third line |
|
one lineline 2A third line |
You can combine the two statements as well. Just remember that you go to the next line after you've printed something with println. This program:
|
will have the following output:
abc defghijkl mnopqr |
One thing to note is that spaces inside quotes will get printed exactly as you type them. Generally, spaces and blank lines elsewhere will be ignored. The output of this program
|
would be
a space then several spaces the spaces outside the quotes are ignored but don't do this as the program becomes very hard to read |
The program should look like this:
|
even though both versions produce exactly the same output.
There is one problem with this system. What happens if we want to include quotation marks in our output? We've been using quotation marks to begin and end the strings we've been printing. So if we wanted this output:
She said, "And I quote". |
we might try typing this: println("She said, "And I quote".");
It won't work because we now have a string She said, and then more stuff. We need a way of saying that the second and third double quotes do not indicate the beginning or ending of a string but should be printed as characters. The way we do that is by putting a backslash character in front of the double quote. The correct way of doing the previous example is: println("She said, \"And I quote\".");
The backslash doesn't get printed. It is known as an escape character. It indicates that the next character is a special character. So what happens if we want to print a backslash character? We use two backslashes. The first is the escape character and the second is the special character we want (the backslash).
println("What \"will\" this \\do\\?");
would produce
What "will" this \do\? |
There are a couple of other special characters that Processing has:
\n gives you a newline character (makes you go to the next line).
\t gives a tab character.
|