Generative art made with Processing or p5.js begins with a short set of rules written as code, which the computer then carries out with some freedom of its own. Philip Galanter’s definition covers far more than software: generative art is any practice where the artist uses a system, “such as a set of natural language rules, a computer program, a machine, or other procedural invention,” set in motion “with some degree of autonomy contributing to or resulting in a completed work of art” (Philip Galanter, “What is Generative Art?”). The phrase “natural language rules” is the link between today’s sketches and the wall drawings Sol LeWitt began issuing as written instructions decades earlier. Casey Reas, one of the two people who started Processing, made that link explicit by translating LeWitt’s instructions into software.

Creators: How To Draw With Code | Casey Reas

At a glance

  • What it is: art made by a system, such as a program, set in motion with some autonomy (Galanter)
  • Processing: begun in spring 2001 by Ben Fry and Casey Reas at the MIT Media Lab (Processing)
  • p5.js: a free, open-source JavaScript library, created by Lauren Lee McCarthy in 2013 (p5.js)
  • Core loop: `draw()` runs repeatedly, by default trying for 60 times a second (p5.js reference)
  • Key tools: `random()`, `randomSeed()`, Perlin `noise()` (p5.js reference)
  • Main drawback: an unseeded random sketch will not produce the same image twice (p5.js reference)

Instructions Before Software

LeWitt’s machine

In “Paragraphs on Conceptual Art,” published in 1967, LeWitt described the artist’s idea as “the machine that makes the art” and wrote that “the fewer decisions made in the course of completing the work, the better,” as the National Gallery of Art summarises the essay (National Gallery of Art). His wall drawings were carried out by draftspeople working from his instructions, a division of labour Casey Reas describes in detail (Whitney ARTPORT).

That arrangement is close enough to programming that Reas built a project on it. In the text accompanying his Software Structures, commissioned for the Whitney Museum’s online ARTPORT, he writes that LeWitt “writes programs for people to execute and interpret rather than for machines” (Casey Reas, Software Structures, Whitney ARTPORT). Reas says LeWitt’s wall drawings changed his own practice, above all in the way they separate the concept of a work from its physical execution.

Pen plotter drawing fine black wandering curves on white paper.

Three Wall Drawings Run as Code

Who makes the decisions

Reas’s translations are instructive because they show where the decisions move. Turning LeWitt’s Wall Drawing #85 into code he calls “an exercise in translation,” noting that it is the programmer, not the draftsperson, who now makes the choices the instructions leave open (Whitney ARTPORT). Executing Wall Drawing #106 in software, he writes, “brings into focus the coarse resolution of the screen,” and he made the number of arcs respond to the position of the mouse.

Wall Drawing #358 on a 50-pixel grid

The clearest case is Wall Drawing #358. Reas says he “chose to make a grid of 50 pixels,” and that his program picks the direction of each arc at random, where LeWitt’s draftspeople would have decided (Whitney ARTPORT). Randomness takes the place of a human hand.

The experiment went one step further with Software Structure #003, for which three programmers, Jared Tarbell, Robert Hodgin and William Ngan, were commissioned to implement the same structure. Three people reading one set of rules produced three works, exactly as several draftspeople produce different versions of one LeWitt instruction.

The Whitney later put the two traditions in one room. Its 2018–19 exhibition Programmed: Rules, Codes, and Choreographies in Art, 1965–2018 listed Reas’s {Software} Structure #003 A and his Sol LeWitt Wall Drawing #358 (both 2004 and 2016) alongside LeWitt’s own works, in a show built around pieces “programmed” through instructions, rules and code (Whitney Museum of American Art).

Processing: A Sketchbook That Runs

MIT, 2001

The tool Reas used came out of the same lab culture. Processing’s own history says he and Ben Fry began it in spring 2001, as graduate students at the MIT Media Lab in John Maeda’s Aesthetics and Computation research group, and that it “grew directly out of Maeda’s Design By Numbers project,” released in 1999 (Processing). It was created “to serve as a software sketchbook and to teach programming fundamentals within a visual context,” and it has always been free, open source and available on Mac OS, Windows and Linux.

The word “sketchbook” matters. Reas’s stated aim in Software Structures was to make programming “as immediate and fluid as drawing” (Whitney ARTPORT), and a Processing file is still called a sketch.

Writing the rule in English first

Reas’s later Process series kept the LeWitt habit of starting with words. In his Process Compendium, an Element is “a simple machine that is comprised of a Form and one or more Behaviors,” and a Process defines an environment for Elements and decides how their relationships are made visible; the English text, written to be translated into software, is the primary part of the work (Casey Reas, Process Compendium). Process 4 begins: “A rectangular surface filled with varying sizes of Element 1.” Reas notes that the translation is itself an interpretation, because the text leaves many choices to the programmer. Processes 1 to 3 were made in 2004 as the Structure works for the Whitney’s ARTPORT, and the Process Compendium 2004–2010 documents Processes 4 through 18.

Gallery wall marked with a faint pencil grid, with ladder, straightedge and pencils ready for a wall drawing.

p5.js: The Same Idea in a Browser

JavaScript, 2013

p5.js carries the Processing approach onto the web. Its project page calls it “a friendly tool for learning to code and make art” and a free, open-source JavaScript library, lists Lauren Lee McCarthy as its creator and lead from 2013 to 2020, and places it within the Processing ecosystem alongside Processing itself, Processing.py and versions for Android and Raspberry Pi (p5.js). The Processing Foundation heads its list of supporters.

setup() and draw()

A p5.js sketch is organised around two functions. Code in `setup()` runs once; `draw()` is “called repeatedly while the sketch runs,” and by default tries to run 60 times per second, though the real rate depends on many factors (p5.js reference). A still image can be made entirely in `setup()`. An animation, or a drawing that builds up mark by mark, lives in `draw()`.

Chance, Seeds and Noise

Two kinds of unpredictability

Generative sketches usually rely on two sources of variation, and the p5.js reference distinguishes them. Values from `random()` and `randomGaussian()` “can change by large amounts between function calls” (p5.js reference). Perlin noise behaves differently: `noise()` always returns values between 0 and 1, and successive values can be made smooth, so a line or a field built from it drifts instead of jittering. The reference records the function’s origin: “Ken Perlin invented `noise()` while animating the original Tron film in the 1980s.”

Seeds make a work repeatable

Chance in software is reproducible on request. `randomSeed()` “Sets the seed value for the random() and randomGaussian() functions” (p5.js reference), and `noiseSeed()` makes a sketch generate the same sequence of noise values each time it runs (p5.js reference). Without a seed, every run is a new image; with one, a particular result can be returned to, printed or shown again. The seed becomes a kind of edition number.

A short sketch

The example below, written for this post, draws a stack of horizontal lines displaced by Perlin noise. Changing the seed number gives a different but repeatable drawing.

“`javascript
function setup() {
createCanvas(800, 450);
randomSeed(358);
noiseSeed(358);
background(245);
stroke(20, 60);
noFill();
for (let y = 0; y < height; y += 6) {
beginShape();
for (let x = 0; x <= width; x += 10) {
vertex(x, y + 40 * (noise(x * 0.005, y * 0.01) – 0.5));
}
endShape();
}
}
“`

Read as an instruction in LeWitt’s sense, it says: draw horizontal lines six units apart across the surface, each bent up and down by a slowly varying amount. A person with a pencil could follow that. The program follows it faster and the same way every time the seed stays at 358.

Where to see examples

Online, where the works run

Reas’s Software Structures text and the works it describes are published on the Whitney Museum’s ARTPORT (Whitney ARTPORT), and the Whitney keeps a page for the Programmed exhibition (Whitney Museum of American Art). The Process Compendium texts are on Reas’s own site (reas.com). Processing and p5.js are free to download or use from their project sites (Processing; p5.js). Online pages and exhibitions change, so the official pages should be checked for what is currently available.

Frequently asked questions

What is generative art?

In Philip Galanter’s definition, any art practice in which the artist uses a system, such as rules or a computer program, set in motion with some autonomy to produce the work (Galanter).

What is the difference between Processing and p5.js?

Processing was started in 2001 by Ben Fry and Casey Reas as a software sketchbook (Processing); p5.js, created by Lauren Lee McCarthy in 2013, is a free JavaScript library within the same Processing ecosystem (p5.js).

Is p5.js free?

Yes; its project page describes it as a free and open-source JavaScript library (p5.js).

What does noise() do in p5.js?

It returns Perlin noise values between 0 and 1 that can change smoothly, unlike `random()`, whose values can jump by large amounts (p5.js reference).

How do I make a generative sketch produce the same image every time?

Set a seed with `randomSeed()` for random values and `noiseSeed()` for noise values (p5.js reference; p5.js reference).

Books and supplies

Processing, Second Edition: Casey Reas’s programming handbook. See it on Amazon (affiliate link).

Getting Started with p5.js: Lauren McCarthy’s introduction to p5.js. See it on Amazon (affiliate link).

As an Amazon Associate I earn from qualifying purchases. A commission may be earned if you buy through this link, at no extra cost to you.

Sources