Processing Basics

What is Processing?

Processing was designed specifically for use with audiovisual media and arts. It has been developed since 2001 at MIT (Boston/USA) under the direction of Ben Fry and Casey Reas (later also Daniel Shiffman). Processing represents a simplified form of the programming language Java, and was developed to program visual elements and interaction. Accordingly, Processing's target audience consists primarily of designers and artists, who are first and foremost artists and only secondarily programmers. Over the years, several other projects have emerged from Processing, the best known of which is certainly the Arduino hardware project, whose programming environment is based on Processing. Recent updates in Processing itself represent special modes of the development environment, which make it possible to develop for web browsers in JavaScript-Modusarrow-up-right, for β†’ Android-Devicesarrow-up-right or in β†’ Pythonarrow-up-right.

Figure: History of the Processing projects

Pros

  • Open Source

  • Availability, accessability

  • Based on Java, the knowledge learned can therefore also be used in Java and Android devices

  • Available on all major desktop operating systems

  • Exists for over 20 years, therefore many libraries and good documentation

Cons

  • Some things are not available "out of the box" and you might have to develop them yourself

  • Java needs its runtime environment and is less fast than e.g. C++

The IDE (integrated development environment) of Processing

The sketch window

Figure – Processing's sketch window

An overview of the basic functions can also be found here on the Processing website: β†’ Environmentarrow-up-right

Figure – Processing's default output window

The output window

Besides the sketch window, Processing provides an output window, which opens automatically when you press the Run button. It shows the program that was previously created in the sketch window, in the example below these are just two simple lines:

The size of the output window is defined by the function size(). Fullscreen output is achieved by fullScreen(DISPLAY); where DISPLAY is an integer indicating if the sketch should run in fullscreen on the internal screen or on a second screen/video-projector.

Basic structure of a processing sketch

Processing programs are called "sketches". Each sketch sits in its own folder. This folder is created automatically by Processing and is given the same name that was defined for the sketch when it was saved.

Starting coding with Processing ist easy. To write a program you can just type some lines of code:

However, a typical program in Processing consists of the two functions setup() and draw() (an explanation of what functions exactly are follows below):

Basic programming strategies in Processing – Overview

Variables

Iteration

Conditionals

  • If statement:

    • Used to check if a specific condition is true (e.g., integer == 1). If the condition is true, the code inside the curly braces {} will execute.

  • Switch statement:

    • Used when you want to compare a variable (like integer) against several different values (e.g., 1, 2).

    • Each case represents a possible value for the variable, and the code under that case runs if the variable matches the value.

    • The break statement ensures that once a case is executed, the program doesn't continue checking the other cases.

Functions

Recursion

chevron-rightInteractive variation (coded/adapted in the lecture)hashtag
  • Recursion: The drawBranch() function calls itself inside the function to create smaller and smaller branches.

  • Base Case: The recursion stops when the branch length (len) becomes less than or equal to 2.

  • Transformations: Each time the function is called, the position is moved to the end of the current branch using translate(). The rotate() function turns the drawing direction to create branches on either side.

  • Fractal Structure: Since each recursive call generates two smaller branches, this creates a fractal-like tree structure that becomes increasingly detailed with each recursion.

Iterations of a visually slightly more complex recursive process. http://andreaspirchner.com/museums-in-the-digital-space/arrow-up-right

L-Systems

https://www.youtube.com/watch?v=1eNHrRe4Sqkarrow-up-right

https://en.wikipedia.org/wiki/L-systemarrow-up-right

Working with external libraries

Peasy Cam

Last updated