Introduction to Processing (Java)
Processing is an environment made as an add-on for programming animations and visual applications, with good and easy interaction with the user.
Processing is a flexible software framework and development environment, designed mainly to make visual artistic expression through programming easier. Its purpose is to bring programming closer to artists, designers and others without previous coding experience.
It is written in Java and can be seen as an add-on that provides support, i.e. an API with functions for creating animations and visual applications. It is based on writing sketches (sketch).
Processing is open source.
It has its own environment, PDE (Processing Development Environment), where you can choose the language you will write code in. It can also be connected with Eclipse IDE or another Java development tool (IDE), by adding the libraries that contain Processing to the existing Java libraries. At the time this tutorial was written, Processing 4 was used
The API consists of several libraries that, besides the basic functions, support: sending data over a network, reading images from a camera, saving images in pdf format.
Processing was originally designed so that, with its simple syntax and many options for creating graphics, images and animations, it would be easier for developers to build creative animated and interactive applications.
It is still used in server and desktop applications, but if you need to put an animation into a website, it is better to use the JavaScript library for Processing, p5js.
Up to version 3, it was possible to use the Java version of Processing on the web too, but you had to add the processing.js script to the site. Development and support for this script have stopped, and it does not support Processing versions from 3 onward. So if you create a web application as .pde and want to put it into a web page, you first have to rewrite the code you wrote in, e.g., Processing 4 before uploading it to the website, because the new functions are not supported, and then also upload the processing.js library, which translates the code written in Java into JavaScript code. That is why, if you are already making a website and want to enrich it with an animation made in Processing, it is smarter to use the p5js library. Read more about this in the article: happycoding.io/tutorials/p5js/which-processing
Features of Processing
1.
A simple environment: Processing offers a simple development environment that lets you start working quickly. Its interface is minimal and focused on making creative expression easier.
2.
Syntax: Processing uses a simple syntax that is easy to understand, even for those who are new to programming. However, under the hood, Processing relies on Java, which means that users have the full power of Java programming available when they need it.
3.
Graphics and interactivity: Processing is specially designed for drawing graphics and creating interactive visualizations. It has built-in functions for drawing shapes, handling colors, animations and working with images.
4.
Community and resources: There are many resources, including tutorials, books and an online community that gives support and shares code examples.
The programming environment and the language
1. The programming environment: Processing provides an integrated development environment (IDE) that is simple and meant for beginners. This environment lets you write, compile and run code in one interface. The Processing IDE includes tools for drawing, animation and interactivity, which makes it ideal for visual projects.
2. The language: Although Processing is based on Java, it uses a simplified syntax adapted to beginners and people who work in the visual arts. Code written in Processing is translated into Java, which makes it easy to move between Processing and Java.
A library for Java
Library: Processing is also a Java library that can be used inside Java projects. This means you can use Processing's features in standard Java applications, combining Processing's graphics with other Java libraries and tools.
How Processing and Java are combined
- Based on Java: Processing is based on Java, which means that Processing users can use all the features of the Java language. This combines the simplicity of Processing with the power and flexibility of Java.
- Using Java libraries: In Processing you can use any Java library, which extends the features Processing offers.
- Learning: Processing can be a great introduction to programming in Java, especially for visual learners and creative people, because it gives visual results quickly.
Conclusion
Processing is a great tool for artists and designers who want to explore the world of programming through visual projects, while Java gives a solid foundation for developing all kinds of software applications. Combining the two can give a powerful environment for creative and technical development.
The micro:bit workshops are part of the creative programming course organized by the Regional Center for Talents "Mihajlo Pupin" in Pančevo:
Creative programming (in Serbian)
The PDE environment
Start Processing 4 by double-clicking its icon, and the following environment will open:

If you are a beginner, you can choose one of the offered examples and then change the existing code, or start an application from the beginning. To program in Processing you need basic knowledge of the JAVA programming language or of one of the supported ones: JavaScript, Python etc. This tutorial is based on the Java programming language.
Organizing code in Processing
The files in which code is written are actually sketches, and they are kept in a folder called the sketchbook. This folder can be changed in the PDE by clicking
File->Sketchbook
This can be seen in the following picture:

An application can be exported by clicking
File -> Export Application
From Java to Processing
If you know the basics of programming in JAVA, as well as the basics of object-oriented programming – classes, objects, inheritance etc. – then, assuming the needed Processing libraries have been added, the code in the Eclipse IDE would look, for example, like the following picture:

At the start of the main class, to program in Processing, you need to import the basic library:
import processing.core.*;
This is only the basic library; specific ones are added when needed.
So the starting class must inherit the PApplet class. Also note the overridden methods from the PApplet class: settings, setup (in figure 3) and draw (see figure 4).

In the navigator on the right you can see the headers of these methods, and clicking a header puts the cursor on that method.
Coding a sketch in the PDE environment is different, because in the background the basic libraries are already imported, the header line of the main class is written, and the methods setup and draw are inserted for overriding,
So you do not need to write, e.g., “class Glavna” (main class), and you do not need to write “import processing.core.*;” (see figure 2).
The methods settings, setup and draw from the PApplet class
Animations are made by first creating objects and setting them to their starting state, and then changing the state of the objects through frames at a certain time interval, e.g. 0.05 s. So we need, on one side, methods that create the objects in their starting state and are called only when the application starts, and on the other side a method that changes these states and is called periodically, according to the defined time interval (0.05 s in the example). The methods settings and setup belong to the first group: they define the starting state and are called only once, while the method draw is called every dt seconds.
This method takes care of the needed changes of the state of objects or variables, and also of drawing these objects on the screen.
The example in the pictures shows balls moving randomly, and we can see that these methods are used here for the following:
- settings: Sets the display size to full screen
- setup: Creates an array of balls at random
- draw: Moves and draws the balls
Introduction to Processing – video
A program in the PDE environment
In the PDE environment we would put this same example inside a new sketch. When a new sketch is opened, we rename it, for example, to BouncesGame (see the picture). The example shows how to simulate the chaotic motion of balls in Processing.

Here we type the code that belongs to the main class, which will be called “BouncesGame”, and after running, a folder with the same name will be created:

The starting class is a bit different from the starting class developed in the Eclipse IDE environment:
Code from figure 7: The starting file in Processing – BouncesGame
Bounce[] bounces;
@Override
public void settings() {
fullScreen();
}
@Override
public void setup() {
bounces = new Bounce[100];
for (int i = 0; i < 100; i++) {
float x = (float) (width * Math.random());
float y = (float) (height * Math.random());
Bounce b = new Bounce(x, y, 5);
bounces[i] = b;
}
}
@Override
public void draw() {
this.background(color(200));
// completed – the rest of the method was not visible in the picture:
for (Bounce b : bounces) {
b.move(width, height);
ellipse(b.center.x, b.center.y, 2 * b.r, 2 * b.r);
}
}
Here there is no class header and no import of the basic library; instead there are variable declarations and the methods settings, setup and draw just like in the Eclipse version.
The other class, which describes a ball (Bounce), is written the same way as in the Eclipse IDE environment, as you can see in the following picture:
Code from figure 7: Example in Processing: BouncesGame – the Bounce class
import processing.core.PVector;
public class Bounce {
float r;
PVector center;
PVector speed;
public Bounce(float x, float y, float r) {
super();
center = new PVector(x, y);
speed = new PVector((float) (10 * Math.random()), (float) (10 * Math.random()));
this.r = r;
}
public Bounce() {
super();
}
void move(double w, double h) {
center.x += speed.x;
center.y += speed.y;
if (center.x < 0 || center.x > w) {
speed.x *= -1;
}
if (center.y < 0 || center.y > h) {
speed.y *= -1;
}
}
}
After running, you will see the balls moving chaotically on the screen:

Check your knowledge
Open the quiz
Quiz: Introduction to Processing
1. What is Processing?
2. How many times does the function setup() run?
3. What does draw() do?
4. What is the development environment of Processing called?
JAVA AND PROCESSING - INTRODUCTION
Processing is an environment that is built as a plugin for programming animations as well as visual applications, with good and easy interaction with the user.It is written in Java and can be treated as a plugin that contains support ie. An API with functions for creating animations and visual applications. It is based on writing a sketch.
Processing is open source.
It has its own environment PDE (Processing Development Environment) for work where you can choose the language in which the code will be written. It can also be connected to the Eclipse IDE or some other Java development tool (IDE), by adding the libraries that contain processing to the existing Java libraries. At the time of writing the tutorial, Processing 4 is used
The API consists of several libraries that, in addition to the basic functions, support: sending data over the network, reading images from the camera, saving images in pdf format.
Processing was originally designed to make it easier for developers to develop creative animated and interactive applications with its simple syntax and numerous possibilities for creating graphics, images and animations.
It is still used in server and desktop applications, but if it is necessary to incorporate some animation into a website, it is better to use the javascript library for processing p5js.
Until version 3, it was possible to use the processing version in Java, but it was necessary to add the prosessing.js script inside the site. Development and support for this script has ceased to exist and does not support versions of processing from 3 onwards. So, if you create a web application as a ".pde" and want to embed it in a web page, you must first modify the code you wrote in version processing 4, for example. before uploading it to the website because the new functions are not supported, and then uploading the processing.js library, which will translate the code written in java into javascript code. That is why it is smarter, if you are already creating a website and want to enrich it with some animation created in processing, to use the p5js library for development. Read more about it in the article: happycoding.io/tutorials/p5js/which-processing
Installation of processing
It can be downloaded from the site:processing.org/download
PDE environment
Start processing 4 by double-clicking on the icon and the following environment will start:
Code organization in processing
The files in which the code is written are actually sketches and they are placed in a folder called sketchbook. This folder can be changed using PDE by clicking onFile->Sketchbook
This can be seen in the following image:
File-> Export Application
From Java to Processing
If you are familiar with programming in JAVA, the basics, as well as the basics of object-oriented programming: classes, objects, inheritance, etc. then assuming that the necessary libraries for processing have been added, the code in the Eclipse IDE environment would look, for example, as in the following figure:
So the initial class must inherit from the PApplet class. You should also notice the revised methods from the PApplet class: settigs, setup (in Figure 3) and draw (see Figure 4).
The sketch coding in the PDE environment is different because the import of the basic libraries has already been done in the background, the title line of the main class has been written and the setup and draw methods have been inserted for overriding.
Therefore, it is not necessary to write: "class Main" e.g. and it is not necessary to write "import processing.core.*;". (see figure 2).
Metods: settings, setup, draw from PApplet class
Given that animations are obtained by first creating objects and initializing them to their initial state, and then changing the state of objects through Frames at a certain time interval, e.g. 0.05 sec, methods are needed that, on the one hand, create objects in the initial state and are called only at the beginning of the application launch, and on the other hand, a method that changes these states and is called periodically according to the defined time interval (0.05 sec in the example).The settings and setup methods are among the first to define the initial state and are called only once, while the draw method is called every dt seconds.This method takes care of the necessary changes to the state of objects or variables, and also of drawing these objects to the screen.
the example in the pictures shows the movement of the balls, randomly determined and it can be seen that the methods mentioned here are used for the following:
- settings: Sets the display size to full screen
- setup: Creates a random array of balls
- draw: Balls are moved and drawn
Program in PDE environment
This same example in use in a PDE environment would place inside a new scatch. When a new scatch is opened, we will rename it to e.g. BouncesGame (see image). The example shows how to simulate the chaotic movement of balls in processing.
Druga klasa koja opisuje lopticu(Bounce) se neće razlikovati od pisanja u Eclipse IDE okruženju što se može vidti na sledećoj slici:
| Previous |< Applications in JAVA-examples |
Next Basics of processing using Java >| |
