Programming Modes
Basic Mode
In basic mode, you simply type individual lines of commands sequentially into the text
editor window, without the added complexity of more complex structures, such as functions
or classes. The following code is
structured in basic mode and generates a simple red circle, with a black stroke on a yellow
background:
size(200, 200);
background(255, 255, 0);
stroke(0);
fill(255, 0, 0);
int x = 100;
int y = 100;
int w = 140;
int h = 140;
ellipse(x, y, w, h);
Continuous mode
In continuous mode, you build upon basic mode, with the edition
of code structures called
functions and
classes.
Functions are the main building
blocks used in
procedural programming, and are simply groupings of lines of code that
execute only when they are explicitly called.
Classes are more complicated structures
than functions, and are utilized in OOP.
In
basic mode, code is executed linearly (line by line). Functions and classes, on the other
hand, allow code to be executed nonlinearly.
In continuous mode, two basic Processing functions are provided:
void setup(){
}
void draw(){
}
The
setup() function is called only once, at the start of the program. This is the place
where you normally initialize variables that will be used later in the program. Adding the
setup() function to your sketch allows you to add your own additional custom functions
and classes.
The
draw() function adds animation capabilities to your sketch and has a
built-in loop, more accurately called a
thread or
timer. By default, adding the
draw() function
to your sketch causes any code between the curly braces of this structure to continuously
execute.
Java mode
This mode allows you to work in pure Java, from directly within the Processing text editor.
Java mode is extremely flexible, giving you access to the entire Java API.