Code in 2011
Crosshatch studies in Processing #1
I've started doing one short Processing program a day; here are some crosshatching studies done over the course of a few days. The past few years I've been carrying around those storyboarding Moleskine journals and have been filling them up with random line work. These programs are meant to replicate some of the idioms in those sketchbooks. Code (visit Processing.org) follows...
An interesting byproduct of the algorithm in the last one is that the lines from one square continue into the next. I'm thinking of using this in the next iteration with hexagonal pixels where each side has a fixed interface where lines can enter and leave.
import processing.pdf.*; int w = 1000; int h = 1000; int base_radius=100; int SCRIBBLE = 0; int HATCHING = 1; PImage img; void setup() { size(w, h); //size(w, h, PDF, "foo.pdf"); noLoop(); beginRecord(PDF, "foo.pdf"); } void draw () { stroke(0); smooth(); background(255); for (int i=0; i<5; i++) { for (int j=0; j<5; j++) { for (int k=0; k<random(5)+1; k++) { float r = random(base_radius-20)+20; translate(j*2*base_radius+base_radius, i*2* base_radius+base_radius); float angle = PI/random(3)+1; rotate(angle); drawCircle(0, 0, r); rotate(PI/3.0); drawCircle(0, 0, r); resetMatrix(); } } } endRecord(); } void drawCircle(float centerx, float centery, float radius) { int segments =20; float angle1 = 0; int midpoint=0; int steps =20; float scribVal = 0.5; // (x-centerx)**2 + (y-centery)**2 = r**2 // x = sqrt(r**2 - (y-centery)**2) + centerx // y = sqrt(r**2 - (x-centerx)**2) + centery int slice_width = 3; float slices = radius / slice_width; int messiness = 1; for (float i=0; i< 2*slices; i++ ) { float startx=centerx-radius+(i*slice_width) + random(messiness)-messiness/2; float starty=sqrt(sq(radius) - sq(startx-centerx)) + centery + random(messiness)-messiness/2; float endx=startx+random(messiness)-messiness/2; float endy=centery-sqrt(sq(radius) - sq(startx-centerx)) + random(messiness)-messiness/2; scribble(startx, starty, endx, endy, steps, scribVal, SCRIBBLE); } } void scribble( float x1, float y1, float x2, float y2, int steps, float scribVal, int style) { /* Scribble Plotter by Ira Greenberg. */ float xStep = (x2-x1)/steps; float yStep = (y2-y1)/steps; float graylevel = 0; strokeWeight(.25); for (int i = 0; i < steps; i++) { print(i+" "); graylevel = 0; // random(100); stroke(graylevel); if (style == SCRIBBLE) { if (i < steps-1) { line(x1, y1, x1+=xStep+random(-scribVal, scribVal), y1+=yStep+random(-scribVal, scribVal)); } else { line(x1, y1, x2, y2); } } else if (style == HATCHING) { line(x1, y1, (x1+=xStep)+random(-scribVal, scribVal), (y1+=yStep)+random(-scribVal, scribVal)); } } println(); } float rads(float n) { // Return an angle in radians return (n/180.0 * PI); }