/* knmProcessing.pde (c) 2007, 2010 Alexander Ness Revised 100730 Draw a page of "KNM" icons. The top line presents undistorted icons; the icons in each subsequent line become more and more distorted. */ import processing.pdf.*; // PDF library // size of each tile float sqSize = 10; // spacing between tiles float margin = 0; float dx = margin + sqSize; float dy = -1 * (margin + sqSize); // design spacing float xShift = 24 * dx; // horizontal spacing between "KNM" icons float yShift = -12 * dy; // vertical (line) spacing void setup() { /* PDF Setup */ rectMode(CENTER); size(17 * 144, 11 * 144, PDF, "knmPosterNew.pdf"); background(255, 255, 255); fill(0); noStroke(); noLoop(); } void draw() { // starting position translate(-xShift + 50, 100); // twelve rows of KNM designs for (float i = 0; i < 13; i = i + 1 ) { pushMatrix(); // save transformation state for (float j = 0; j < 10; j = j + 1 ) { translate(xShift, 0); drawKNM(0, i+j/20); // bend, explode } popMatrix(); // restore transformation state translate(0, yShift); // move to the next line // change square size sqSize = sqSize - random(1, 2); margin = margin + random(1, 2); } exit(); } void drawKNM(float bend, float explode) { /* Draw a "KNM" icon. */ drawK(bend, explode); translate(6 * dx, 0); drawN(bend, explode); translate(6 * dx, 0); drawM(bend, explode); translate(-12 * dx, 0); } boolean[] bools(int num, boolean val) { /* Return an array of booleans. */ boolean[] bools = new boolean[num]; for (int i = 0; i < bools.length; i++) { bools[i] = val; } return bools; } void drawPath(int[] path, boolean[] bools, float bend, float explode) { /* Draw a sequence of squares, following the steps described by `path`. `bools` is an array of booleans corresponding to `path`, indicating whether or not to draw after each step. */ for (int i = 0; i < path.length; i++) { go(path[i], bools[i], bend, explode); } } void drawSq() { rect(0, 0, sqSize, sqSize); } void drawK(float bend, float explode) { int[] path1 = {2, 2, 6, 6, 9, 9}; int[] path2 = {8, 8, 6, 6, 3, 3}; boolean[] bools2 = {true, false, false, false, true, true}; // lower half drawSq(); drawPath(path1, bools(path1.length, true), bend, explode); translate( -4 * dx, 4 * dy); drawSq(); drawPath(path2, bools2, bend, explode); translate( -4 * dx, -4 * dy); } void drawN(float bend, float explode) { int[] path = {2, 2, 2, 2, 9, 9, 9, 9, 2, 2, 2, 2}; drawSq(); drawPath(path, bools(path.length, true), bend, explode); translate(-4 * dx, -4 * dy); } void drawM( float bend, float explode ) { int[] path = {2, 2, 2, 2, 9, 9, 3, 3, 8, 8, 8, 8}; drawSq(); drawPath(path, bools(path.length, true), bend, explode); translate(-4 * dx, 0); } void go(int direction, boolean drawSq, float bend, float explode) { /* Step in one of eight directions: 1 2 3 4 6 7 8 9 If `drawSq`, draw a square after stepping. `bend` and `explode` distort the geometry. */ rotate(random(-1 * bend, bend)); translate(random(-explode, explode), random(-explode, explode)); switch(direction) { case 1: translate(-1 * dx, dy); break; case 2: translate(0, dy); break; case 3: translate(dx, dy); break; case 4: translate(-1 * dx, 0); break; case 6: translate(dx, 0); break; case 7: translate(-1 * dx, -1 * dy); break; case 8: translate(0, -1 * dy); break; case 9: translate(1 * dx, -1 * dy); break; } if (drawSq) { drawSq(); } }