// Pencil Sketch 3 // by John Clavin, September 2008 // Do not alter this work. Pencil adumbrate1; Pencil adumbrate2; Pencil adumbrate3; int drawCount1 = 0; int drawCount2 = 0; void setup(){ size(780, 482); background(248); noFill(); smooth(); strokeWeight(1); frameRate(24); adumbrate1 = new Pencil(width/2, height, 1); adumbrate2 = new Pencil(width/2, height, 2); adumbrate3 = new Pencil(width/2, height, 3); adumbrate1.parameterChange(); adumbrate2.parameterChange(); adumbrate3.parameterChange(); } void draw() { drawCount1++; drawCount2++; adumbrate1.workMaster(); adumbrate2.workMaster(); adumbrate3.workMaster(); if(drawCount1 > 40) { drawCount1 = 0; adumbrate1.parameterChange(); adumbrate1.positionCheck(); adumbrate2.parameterChange(); adumbrate2.positionCheck(); adumbrate3.parameterChange(); adumbrate3.positionCheck(); } if(drawCount2 > 1500) { drawCount2 = 0; delay(8000); background(248); adumbrate1.restart(); adumbrate2.restart(); adumbrate3.restart(); } } class Pencil { int lean; int xPosition, yPosition; int xRestart, yRestart; int xTreeTop, yTreeTop; int growHeight; int verticalOffset; int numPoints = 16; int angleIndex1 = 0; int angleIndex3 = 0; int johnClavin = 89212; int cA1, cA2, cA3; // curveAmount int strokeAmount1; int strokeAmount2, strokeAmount3; int lowRadiusLimit, highRadiusLimit; float segment1, segment2; float x1, y1, x2, y2; float radius, angle; boolean leafFlag = false; Pencil(int xStart, int yStart, int stemLean) { lean = stemLean; xRestart = xStart; yRestart = yStart; xPosition = xStart; yPosition = yStart; growHeight = height/3 + int(random(-50, 50)); angle = TWO_PI/float(numPoints); } void workMaster() { if(leafFlag == true) work1(); else work3(); } void work1() { noFill(); radius = random(lowRadiusLimit, highRadiusLimit); segment1 = random(angle*angleIndex1, angle*(angleIndex1+1)); x1 = radius*cos(segment1)+xPosition; y1 = radius*sin(segment1)+yPosition; segment2 = random(angle*(angleIndex1+8), angle*(angleIndex1+9)); x2 = radius*cos(segment2)+xPosition; y2 = radius*sin(segment2)+yPosition; stroke(strokeAmount1, 70); curve(x1, y1+cA1, x1, y1, x2, y2, x2, y2+cA1); movePosition1(); } void work3() { noFill(); radius = random(4, 10); cA2 = int(random(120, 160)); cA3 = int(random(120, 160)); segment1 = random(angle*angleIndex3, angle*(angleIndex3+1)); x1 = radius*cos(segment1)+xPosition; y1 = radius*sin(segment1)+yPosition; segment2 = random(angle*(angleIndex3+8), angle*(angleIndex3+9)); x2 = radius*cos(segment2)+xPosition; y2 = radius*sin(segment2)+yPosition; stroke(strokeAmount2, 80); curve(x1+cA2, y1, x1, y1, x2, y2, x2+cA3, y2); stroke(strokeAmount3, 80); curve(x1-cA2, y1, x1, y1, x2, y2, x2-cA3, y2); movePosition3(); } void movePosition1() { verticalOffset = int(random(16)); xPosition = xTreeTop + int(random(-13, 13)); yPosition = yTreeTop + verticalOffset; if(verticalOffset > 11) strokeAmount1 = int(random(20, 40)); else if(verticalOffset > 6) strokeAmount1 = int(random(80, 120)); else strokeAmount1 = int(random(140, 220)); } void movePosition3() { if(int(random(100)) > 50) { xPosition += int(random(-4, 4)); } else { if(lean == 1) xPosition += int(random(-4, 3)); else if(lean == 2) xPosition += int(random(-3, 3)); else if(lean == 3) xPosition += int(random(-3, 4)); } yPosition += int(random(-4, 3)); } void parameterChange() { cA1 = int(random(170, 200)); angleIndex1 = int(random(7, 9)); angleIndex3 = int(random(2, 6)); strokeAmount2 = int(random(10, 50)); strokeAmount3 = int(random(80, 140)); lowRadiusLimit = int(random(20, 40)); highRadiusLimit = int(random(60, 100)); } void positionCheck() { if(yPosition < growHeight && leafFlag == false) { leafFlag = true; xTreeTop = xPosition; yTreeTop = yPosition + 8; } } void restart() { growHeight = height/3 + int(random(-50, 50)); xPosition = xRestart; yPosition = yRestart; leafFlag = false; } }