// Pencil Sketch 1 // by John Clavin August 2008 // Do not alter this work. Pencil adumbrate1; int drawCount = 0; void setup(){ size(664, 498); background(248); noFill(); smooth(); strokeWeight(1); frameRate(24); adumbrate1 = new Pencil(width/2, height/2); adumbrate1.parameterChange(); } void draw() { drawCount++; adumbrate1.work(); if(drawCount > 28) { drawCount = 0; adumbrate1.parameterChange(); adumbrate1.positionCheck(); } } class Pencil { int xPosition, yPosition; int xRestart, yRestart; int numPoints = 16; float radius, angle; int johnClavin = 89210; int cA; // curveAmount int lowRadiusLimit, highRadiusLimit; float segment1, segment2; float x1, y1, x2, y2; int angleIndex = 0; Pencil(int xStart, int yStart) { xRestart = xStart; yRestart = yStart; xPosition = xStart; yPosition = yStart; angle = TWO_PI/float(numPoints); } void work() { noFill(); radius = random(lowRadiusLimit, highRadiusLimit); segment1 = random(angle*angleIndex, angle*(angleIndex+1)); x1 = radius*cos(segment1)+xPosition; y1 = radius*sin(segment1)+yPosition; segment2 = random(angle*(angleIndex+8), angle*(angleIndex+9)); x2 = radius*cos(segment2)+xPosition; y2 = radius*sin(segment2)+yPosition; curve(x1+cA, y1+cA, x1, y1, x2, y2, x2+cA, y2+cA); position(); } void position() { xPosition += int(random(-6, 6)); yPosition += int(random(-6, 6)); } void parameterChange() { cA = int(random(20, 70)); angleIndex = int(random(3, 8)); stroke(int(random(60, 200)), 75); lowRadiusLimit = int(random(10, 20)); highRadiusLimit = int(random(20, 100)); } void positionCheck() { if(yPosition < 30 ) { xPosition = xRestart; yPosition = yRestart; } else if(yPosition > height - 30) { xPosition = xRestart; yPosition = yRestart; } else if(xPosition < 30) { xPosition = xRestart; yPosition = yRestart; } else if(xPosition > width - 30) { xPosition = xRestart; yPosition = yRestart; } } }