Simple Fractals in Processing

I was playing around this week with ways to demonstrate recursion in Processing and also looking into embedding small Processing sketches on the web. So, here is my first experiment, embedded using the processingjs wordpress plugin (I had to use version 1.0 and install manually; couldn’t get the newer version in wordpress’s plugins list to work for some reason).

Simple fractal
Donya Quick

void setup() {

void draw() {
 drawPattern(0,0,width/2, 2); // change last argument to 1 for more detail

void drawPattern(float x, float y, float squareSize, float minSize) {
 rect(x,y,squareSize, squareSize);
 rect(x+squareSize, y, squareSize, squareSize);
 rect(x, y+squareSize, squareSize, squareSize);
 if (squareSize > minSize) {
  drawPattern(x, y, squareSize/2, minSize);
  drawPattern(x+squareSize, y, squareSize/2, minSize);
  drawPattern(x, y+squareSize, squareSize/2, minSize);

Of course, it then got somewhat out of hand with rather a lot more code…enough so that I can’t embed it directly without causing intolerable browser lag.

Leave a Reply

Your email address will not be published. Required fields are marked *