Patterning for Processing

Just tidying the Patterning for Processing library.


Here’s a brief video of it in action.

The program which defines this interactive sketch is :

import patterning.library.Patterning;
import patterning.library.IPattern;

Patterning P;
IPattern myPattern;

void setup() {
  P = new Patterning(this);

void draw() {

  myPattern = P.poly(0, P.zx(4), 0.4, 3+P.mouseY(8),            
                      P.pColor(200,P.mouseY(255),100,200))  );
  myPattern = P.clock((int)P.mouseX(9), myPattern);
  myPattern = P.rotate(PI/4,myPattern);
  myPattern = P.grid(5,myPattern);

void keyPressed() { 

Some notes :

Import the Patterning class itself which is a wrapper for all the Patterning functionality. And the IPattern, an interface to everything which is considered a Pattern. (That’s equivalent to group in the Clojure code.)

In setup, you need to initialize Patterning with a reference to the app, using :

P = new Patterning(this);

P.poly is a wrapper for the poly function, P.clock for clock-rotate, P.grid for grid-layout etc. All functions which create new patterns return new IPatterns. And IPattern is the standard type for passing patterns into and out of layouts like grid.

P.pColor(x), P.pColor(r,g,b), P.pColor(r,g,b,a) are methods for creating Patterning’s p-color.,stroke,fill) creates a map suitable for use as a Patterning style map where strokeWeight is a number, stroke and fill are both p-colors.

The Java wrapper has no lazy lists or easy to assemble sequences … yet.

But I’m using varargs to allow you to stack multiple patterns together using P.stack();

This wrapper currently has only a subset of Patternings functionality. (Full API documentation coming soon). And is far less elegant and flexible. OTOH, it is pretty accessible to an artist who’s only used to Processing.

It also adds functionality that makes it easy to build interactive patterns. Notice the calls to P.mouseX() and P.zx() etc. in the definitions of the patterns.

P.mouseX() and P.mouseY() offer custom access to the mouse position that maps it into the patterning co-ordinate system. P.mouseX(n) or p.mouseY(n) do something similar but map the mouse to values between 0 and n. These make it easy to use the mouse for both positioning / scaling patterns or to define other parameters.

Because the mouse only offers two dimensions, Patterning for Processing also offers the pairs of keys : q & w, a & s, and z & x to adjust 3 further parameters up and down. These three extra controls are called qw, as, and zx and you can access them using P.qw(), and P.zx(). With parameters eg. P.zx(n) the value produced is mapped between 0 and n. (Though note it’s a float and needs to be cast to an int)

In order for the keys to work, you need to capture the keyPressed event and pass it into Patterning using


Leave a Reply