float SKETCH_STEP = 0.055; //default arguments void sketch_line(ArrayList vert, int seed, int max_steps) { float n_wg = 1; //amount which perlin noise affects points float c_wg = 4; //amount to distort by sine curve sketch_line(vert,seed,max_steps,n_wg,c_wg); } //uses stroke() color void sketch_line(ArrayList vert, int seed, int max_steps, float n_wg, float c_wg) //list of points to draw though, first and //last are control points, not draw //set max steps to negative to just draw all of it { randomSeed(seed); if(vert.size() <= 3) { println("Undersized list, only 3 points"); return; } float weight = 1; //initial weight is 1 float max_weight = 1.7; float min_weight = 0.1; float weight_range = max_weight - min_weight; float step = SKETCH_STEP; int steps_taken = 0; float period = 50; //period of sine distortion, not not scaled to 2 pi, just relative float sin_acc = random(0,period) * 2 * 3.14; //distance along line PVector a,b,c,d; //control point, start point, end point, control point a = (PVector)vert.get(0); b = (PVector)vert.get(1); c = (PVector)vert.get(2); for (int i = 3; i < vert.size(); ++i) { d = (PVector)vert.get(i); for (float j = step; j <= 1 + step/2; j += step) //scale from 0 to 1 between each point { //randomly change weight if (weight > max_weight) { weight += random(- weight_range /2 , 0); } else if (weight < min_weight) { weight += random(0,weight_range/2); } else { weight += random(weight_range/2,weight_range/2); } strokeWeight(weight); float start_x = curvePoint(a.x,b.x,c.x,d.x,j - step); float start_y = curvePoint(a.y,b.y,c.y,d.y, j - step); float end_x = curvePoint(a.x,b.x,c.x,d.x, j); float end_y = curvePoint(a.y,b.y,c.y,d.y, j); float sin_acc_old = sin_acc; sin_acc += dist(start_x,start_y,end_x,end_y); line(start_x + n_wg*(noise(start_x,start_y) - 0.5) + c_wg*sin(sin_acc_old / period), start_y + n_wg*(noise(start_x,start_y) - 0.5) + c_wg*sin(sin_acc_old / period), end_x + n_wg*(noise(end_x,end_y) - 0.5) + c_wg*sin(sin_acc / period), end_y + n_wg*(noise(end_x,end_y) - 0.5) + c_wg*sin(sin_acc / period)); steps_taken++; if (steps_taken > max_steps && max_steps > 0) { return; //so line can be animated } } a = b; b = c; c = d; } }