Patterning for Processing

Just tidying the Patterning for Processing library.

screen-0109

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() {
  size(600,600);
  P = new Patterning(this);
}

void draw() {
  background(255);

  myPattern = P.poly(0, P.zx(4), 0.4, 3+P.mouseY(8),            
           P.style(5,P.pColor(P.mouseX(255),255,100),
                      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);
  
  P.draw(myPattern);
  saveFrame();  
}

void keyPressed() { 
  P.keyPressed(key); 
  println(P.zx());
}

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.

P.style(strokeWeight,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(), P.as() 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

P.keyPressed(key);

Leave a Reply