// Pencil Sketch 4b // by John Clavin, September 2008 // Do not alter this work. Pencil hairTree1; int drawCount1 = 0; int drawCount2 = 0; void setup(){ size(780, 482); background(248); noFill(); smooth(); strokeWeight(1); frameRate(24); hairTree1 = new Pencil(width/2, height/2); hairTree1.parameterChange(); } void draw() { drawCount1++; drawCount2++; hairTree1.workMaster(); if(drawCount1 > 40) { drawCount1 = 0; hairTree1.parameterChange(); hairTree1.hairDoneCheck(); } if(drawCount2 > 1200) { drawCount2 = 0; delay(10000); background(248); hairTree1.restart(); } } class Pencil { int xPosition, yPosition; int xTreeTop, yTreeTop; int numPoints = 16; int angleIndex1; int angleIndex3; int johnClavin = 89213; int heightUnit = height/20; int cA1, cA2, cA3; // curveAmount int strokeAmount1; int strokeAmount2, strokeAmount3; float segment1, segment2; float x1, y1, x2, y2; float radius, angle; int hairCount = 0; boolean trunkFlag = false; Pencil(int xStart, int yStart) { xTreeTop = xStart; yTreeTop = yStart; xPosition = xStart; yPosition = yStart; angle = TWO_PI/float(numPoints); } void workMaster() { if(trunkFlag == true) work3(); else work1(); } void work1() { noFill(); angleIndex1 = int(random(0, 8)); selectRadius(); 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; strokeAmount1 = int(random(20, 100)); stroke(strokeAmount1, 70); curve(x1, y1+cA1, xPosition, yPosition, x2, y2, x2, y2+cA1); curve(x1, y1+cA1, x1, y1, xPosition, yPosition, x2, y2+cA1); movePosition1(); } void work3() { noFill(); trunkSize(); 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, 200); curve(x1+cA2, y1, x1, y1, x2, y2, x2+cA3, y2); stroke(strokeAmount3, 200); curve(x1-cA2, y1, x1, y1, x2, y2, x2-cA3, y2); movePosition3(); } void movePosition1() { xPosition = xTreeTop + int(random(-10, 10)); yPosition = yTreeTop + int(random(10)); } void movePosition3() { xPosition = xTreeTop; xPosition += int(random(-2, 2)); yPosition += int(random(-2, 3)); } void selectRadius() { switch(angleIndex1) { case 0: radius = random(140, 200); break; case 1: radius = random(100, 160); break; case 2: radius = random(90, 130); break; case 3: radius = random(90, 106); break; case 4: radius = random(90, 98); break; case 5: radius = random(90, 120); break; case 6: radius = random(100, 160); break; case 7: radius = random(140, 215); break; } } void trunkSize() { if(yPosition < heightUnit * 11) { radius = random(3, 7); cA2 = int(random(77, 118)); cA3 = int(random(77, 118)); strokeAmount3 = strokeAmount2; }else if(yPosition < heightUnit * 12) { radius = random(4, 8); cA2 = int(random(80, 120)); cA3 = int(random(80, 120)); }else if(yPosition < heightUnit * 13) { radius = random(4, 8); cA2 = int(random(85, 125)); cA3 = int(random(85, 125)); }else if(yPosition < heightUnit * 14) { radius = random(5, 10); cA2 = int(random(90, 130)); cA3 = int(random(90, 130)); }else if(yPosition < heightUnit * 15) { radius = random(5, 10); cA2 = int(random(95, 135)); cA3 = int(random(95, 135)); }else if(yPosition < heightUnit * 16) { radius = random(5, 10); cA2 = int(random(100, 140)); cA3 = int(random(100, 140)); }else if(yPosition < heightUnit * 17) { radius = random(6, 12); cA2 = int(random(105, 145)); cA3 = int(random(105, 145)); }else if(yPosition < heightUnit * 18) { radius = random(6, 12); cA2 = int(random(110, 150)); cA3 = int(random(110, 150)); }else if(yPosition < heightUnit * 19) { radius = random(7, 14); cA2 = int(random(115, 155)); cA3 = int(random(115, 155)); }else if(yPosition < heightUnit * 20) { radius = random(8, 16); cA2 = int(random(120, 160)); cA3 = int(random(120, 160)); } } void parameterChange() { cA1 = int(random(300, 400)); angleIndex3 = int(random(2, 6)); strokeAmount2 = int(random(40, 80)); strokeAmount3 = int(random(100, 140)); } void hairDoneCheck() { hairCount++; if(hairCount > 11) { trunkFlag = true; } } void restart() { xPosition = xTreeTop; yPosition = yTreeTop; trunkFlag = false; hairCount = 0; } }