ProcessingLibraryExamples

This is a set of short Java code examples that use the Processing libraries.

These examples may be useful to computer science educators who are teaching a course with the Java language (e.g. AP Computer Science A). Processing provides an easy entry point to computer graphics programming. The Processing libraries are open source and can be used directly from Java programs.

Computer graphics applications are a natural place to use object oriented programming techniques. In addition, concepts such as 2D arrays and recursion can be illustrated nicely with computer graphics.

Install software

Processing (Pay attention to where you install it!)

Java Development Kit JDK SE 8

Text editor or Integrated Development Environment (IDE).

Set the CLASSPATH environment variable

This is the most important part, and the biggest headache:
Setting the CLASSPATH environment variable

Assuming you’ve set your CLASSPATH environment variable correctly, you can run all the examples on the command line:

javac HelloProcessing.java
java HelloProcessing

Processing and the PApplet class

Here’s the red pill. When you run a Processing sketch, all of your global stuff (variables, functions like setup(), draw(), keyPressed(), etc.) gets embedded in a class, and that class is a subclass of PApplet. The PApplet class contains all the Processing functions that you are familiar with, like size() and ellipse().

HelloProcessing.java

Some things to note:

Using external classes

You can write your own Java classes, but you need to give them a reference to the main PApplet class so that it can call the Processing drawing functions.

HelloProcessing2.java
Ball.java

Applications

Object oriented programming techniques are very useful in computer graphics programming, e.g. the Ball class in the HelloProcessing2 example. Here are some other ideas for illustrating concepts from AP Computer Science A with the Processing libraries.

2D array application: Image Processing

ImageProcessing.java

Recursion application: Fractals

Snowflake.java

More info

These code examples are licensed under the GPL v2.0, which means you are free to copy and use the code, but if you distribute a modified program, you must also distribute your code.

You can download all the code examples from the Github repository:
https://github.com/dkessner/ProcessingLibraryExamples

Dr. Darren Kessner
Darren.Kessner@marlborough.org
STEM+ Program
Marlborough School, Los Angeles