 |
Programming_modes
Processing allows people to program within three levels of complexity:
Static Mode, Active Mode, and Java Mode.
Static Mode
This mode is for drawing static images. The following example draws a
yellow rectangle on the screen.
size(200, 200);
background(255);
noStroke();
fill(255, 204, 0);
rect(30, 20, 50, 50);
Active Mode
This mode provides an optional setup() section that is run once when the program begins. The loop() section runs forever until the program is stopped.
This example draws rectangles that follow the mouse position (stored in
the variables mouseX and mouseY). Note also that the call to the background()
method is in setup() because it's only needed once.
void setup()
{
size(200, 200);
background(255);
rectMode(CENTER_DIAMETER);
noStroke();
fill(255, 204, 0);
}
void loop()
{
rect(width-mouseX, height-mouseY, 50, 50);
rect(mouseX, mouseY, 50, 50);
}
Java Mode (Not available until Processing 1.0 Beta)
This mode is the most flexible, and allows for writing complete Java programs
from inside the Processing Environment
This example is the same as above, but done in the Java style:
public class MyDemo extends BApplet {
void setup()
{
size(200, 200);
background(255);
rectMode(CENTER_DIAMETER);
noStroke();
fill(255, 204, 0);
}
void loop()
{
rect(width-mouseX, height-mouseY, 50, 50);
rect(mouseX, mouseY, 50, 50);
}
}
|
|