Previous: Appendix B: Processing Libraries
HelloProcessing
//
// HelloProcessing.java
//
//
// Notes:
//
// 1) The import statement is required to use Processing classes.
//
// 2) When you are in Processing, everything is "global": setup(),
// draw(), all variables declared outside those functions. In
// reality, there is an enclosing PApplet class, of which setup()
// and draw() are member functions. Any "global" variables in
// Processing are actually member variables of your PApplet.
//
// 3) Your main class is actually a sub-class of (extends) PApplet.
// This means that it inherits all of the PApplet member functions
// (i.e. size(), fill(), ellipse()), but also allows you to override
// (write your own) setup() and draw() functions.
//
// 4) There is a settings() function in addition to a setup()
// function, for some technical issue in Processing. Put your
// size() call in settings(), and all other initialization in
// setup().
//
// 5) To run your program, your main() function must call the
// PApplet.main() function with the name of your class as an
// argument.
//
import processing.core.*; // 1
public class HelloProcessing extends PApplet // 2, 3
{
public void settings() // 4
{
size(400, 400);
}
public void setup()
{
x = 0;
}
public void draw()
{
background(0);
ellipse(x, 200, 100, 50);
x++;
}
private float x; // 2
public static void main(String[] args)
{
PApplet.main("HelloProcessing"); // 5
}
}
Next: Ball