Installing Processing 4 and Python Mode

Important – Python Mode is no longer maintained:
the official Processing website says that Python Mode is not maintained and does not recommend using it in Processing 4. It works for simple drawing and animation, but libraries (the serial connection for the micro:bit, sound) often do not work. For new work use Thonny + py5; use this lesson if you already have old sketches.
Environment:
the examples in this lesson are written for Processing Python Mode. If you work in the recommended environment Thonny + py5, most of the code stays the same, and names with a capital letter in the middle are written in lower case with an underscore: mouseX → mouse_x, noStroke() → no_stroke(). See the table of differences.

Lesson 2 of 20 · Python and Processing

Why do we use Processing 4?


In this course we use Processing 4 because it is one of the simplest environments for learning graphics programming.

  • a free and open tool
  • easy to install
  • an ideal environment for graphics, animation and interaction
  • often used in education and creative coding
Note:

If you have already done the lessons from the section Processing with Java, you will notice that the environment is exactly the same. The only difference is that now we use Python instead of the Java language.

A first look at the Processing IDE


When you start Processing, you will see a simple programming interface.

  • Editor – where you write code
  • the Run button ▶ – starts the program
  • the Stop button ■ – stops the program
  • Console – shows messages and errors

Processing is made so that a program can be started with one click, which makes it ideal for beginners.


Step 1: Downloading Processing 4


Visit the official website and download the version for your operating system:

https://processing.org/download

After downloading:

  • Windows: unpack the ZIP file and run processing.exe
  • Mac: drag the application into the Applications folder
  • Linux: unpack the archive and run the script

Processing does not need a classic installation — it works straight after unpacking.


Step 2: Installing Python Mode


By default Processing uses the Java language. To write programs in Python you need to install Python Mode.

  1. Start Processing.
  2. In the menu choose Tools → Manage Modes.
  3. Find Python Mode.
  4. Click Install.

After installing, change the mode in the top right corner from Java to Python.


Checking the installation


Create a new sketch and type the following code:


def setup():
    size(500, 300)

def draw():
    background(220)
Check:

Click the ▶ Run button. If a window with a grey background appears, the installation was successful.

A small experiment:

Change the size of the window:

size(800, 400)
Run the program again and watch the change. Experimenting is the fastest way to learn how Processing works.

Organising projects


Every Processing project is kept in a separate folder called a sketch.

It is good practice to make a separate folder for all the projects from this course.

  • make a folder PythonProcessing
  • keep all the projects in it
  • every project has its own folder

For example:

PythonProcessing/
   first_sketch/
   ball_animation/
   pong/

Other options


Recommended: py5 in Thonny

  • real Python 3 and all Python libraries (for example pyserial for the micro:bit)
  • the Thonny plug-in downloads Java by itself – no manual setup
  • instructions: py5 in Thonny

Processing with Java


The most common mistakes


  • the mode was not changed from Java to Python
  • Python Mode is not installed
  • a mistake in the indentation of the code

If you have problems with Python syntax, see the lesson: Python — the basics of the syntax.


Next step

Now that the environment is ready, we can write the first graphics program.

The first sketch — drawing on the screen


Related topics



Check your knowledge

Open the quiz

Mini quiz: the environment

1. Which language does Processing Python Mode use?




2. Which environment does the course recommend for projects with the micro:bit?