Hardware Reference
In-Depth Information
Every Processing program has two main routines, setup()
and draw() . setup() happens once at the beginning of the
program. It's where you set all your initial conditions, like
the size of the applet window, initial states for variables,
and so forth. draw() is the main loop of the program. It
repeats continuously until you close the applet window.
(integers), booleans (true or false values), Strings of text,
and bytes .
Like C, Java, and many other languages, Processing uses
C-style syntax. All functions have a data type , just like
variables (and many of them are the void type, meaning
that they don't return any values). All lines end with a
semicolon, and all blocks of code are wrapped in curly
braces. Conditional statements (if-then statements),
for-next loops, and comments all use the C syntax as
well. The preceding code illustrates all of these except the
for-next loop.
In order to use variables in Processing, you have to declare
the variable's data type. In the preceding program, the
variables redValue , greenValue , and blueValue are all
float types, meaning that they're floating decimal-point
numbers. Other common variable types you'll use are ints
Here's a typical for-next loop.
Try this in a sketch of its own (to
start a new sketch, select New from
Processing's File menu).
8
for (int myCounter = 0; myCounter <=10; myCounter++) {
println(myCounter);
}
bASIC users: If you've never used a C-style for-next loop, it can seem forbidding. What this bit
of code does is establish a variable called myCounter . As long as a number is less than or equal
to 10, it executes the instructions in the curly braces. myCounter++ tells the program to add
one to myCounter each time through the loop. The equivalent BASIC code is:
for myCounter = 0 to 10
Print myCounter
next
Remote-Access Applications
One of the most effective debugging tools you'll use
when making the projects in this topic is a command-line
remote-access program, which gives you access to the
command-line interface of a remote computer. If you've
never used a command-line interface before, you'll find it
a bit awkward at first, but you get used to it pretty quickly.
This tool is especially important when you need to log into
a web server, because you'll need the command line to
work with PHP scripts that will be used in this topic.
Processing is a fun language to play with
because you can make interactive graphics
very quickly. It's also a simple introduction to
Java for beginning programmers. If you're a Java pro-
grammer already, you can include Java directly in your
Processing programs. Processing is expandable through
code libraries. You'll be using two of the Processing code
libraries frequently in this topic: the serial library and the
networking library.
For more on the syntax of Processing, see the language
reference guide at www.processing.org . To learn more
about programming in Processing, check out Processing:
A Programming Handbook for Visual Designers and
Artists , by Casey Reas and Ben Fry (MIT Press), the
creators of Processing, or their shorter topic, Getting
Started with Processing (O'Reilly). Or, read Daniel
Shiffman's excellent introduction, Learning Processing
(Morgan Kaufmann). There are dozens of other Processing
topics on the market, so find one whose style you like best.
Most web hosting providers are based on Linux, BSD,
Solaris, or some other Unix-like operating system. So,
when you need to do some work on your web server, you
may need to make a command-line connection to your
web server.
NOTE: If you already know how to create PHP and HTML
documents and upload them to your web server, you
can skip ahead to the “PHP” section.
 
Search WWH ::




Custom Search