size (400,400); background (0); //smooth(); // create array of ints to describe a line // x1. y1, x2, y2 float[] line1 = new float[4]; float[] line2 = new float[4]; // setup for slight color varience between cycles float [] strokeColor = {10,10,10}; int strokeAdd = 20; for (int numcyc=0; numcyc<6; numcyc++) { for (int k=0; k<3; k++) { strokeColor[k] = strokeColor[k] + (strokeAdd + random(20)); stroke (strokeColor[0], strokeColor[1], strokeColor[2]); } // fill the array by addressing the location of the array and giving it a value // note that the array starts at position 0 and goes to 3 // even though you initialized the array with the number 4 // summary: 4 positions, numbered 0 through 3 for (int j=0; j<4; j++) { line1[j] = random(0,400); } // find slope of line m = y2-y1 / x2 - x1 float slope1; slope1 = (line1[3] - line1[1])/(line1[2] - line1[0]); println ("slope of first line: " + slope1); // draw out that line by referencing the values now stored in the array strokeWeight (3); line (line1[0], line1[1], line1[2], line1[3]); strokeWeight(1); // draw a given (numlines) number of lines using formula below for (int numlines=0; numlines<200; numlines++) { // generate random # for line2 point 1 x value within range of line1 x values line2[0] = random (line1[0], line1[2]); // find x for that value of y based on equation for line1 // y=m(x-x1) + y1 line2[1] = (slope1 * (line2[0] - line1[0])) + line1[1]; // randomly generate second point for line2. The reason it looks like pine needles is that // the end point of the first line is telling the ends of the smaller lines to cluster around it line2[2] = line1[2] + random(-100,100); line2[3] = line1[3] + random(-100,100); // find slope of new line float slope2 = (line2[3] - line2[1])/(line2[2] - line2[0]); // println ("slope of second line: " + slope2); // Check if lines are parallel (slopes are equal), if so, don't continue with program if (slope1 != slope2) { for (int k=0; k<3; k++) { // small variance in needle color strokeColor[k] = strokeColor[k] + random (-3, 3); stroke (strokeColor[0], strokeColor[1], strokeColor[2]); } line (line2[0], line2[1], line2[2], line2[3]); } } }