EliRosen – 13-9-65
/** * Program to recreate 13/9/65 by Frieder Nake * Creates a random drawing similar to Nake's drawing */ int drawWidth = 600; int drawHeight = 600; float numCircles = random(6,10); int numLines = 11; int numVertices = 8; // Create arrays to hold x, y coords // holds x coords of the vertices float[]x = new float[numVertices]; /* holds y coordinates of the vertices, where the first index refers to the vertical grid line it falls on (counted left to right) * and the second index refers to the zigzag line it belongs to (counted top to bottom) */ float[][]y = new float[numVertices][numLines]; boolean[][]filled = new boolean[numVertices][numLines]; void setup() { size(drawWidth, drawHeight); background(255); smooth(); noFill(); stroke(0); // sets minimum horizontal segment width int minSegmentWidth = 45; //set x position of vertices x[0]=0; for(int i =1; i<numVertices-1; i++) { // creates random horizontal segment widths (vertical grid lines) x[i] = ((drawWidth/(numVertices-1))*i) + random((((drawWidth/(numVertices-1))-minSegmentWidth)*-1), ((drawWidth/(numVertices-1))-minSegmentWidth)); } x[numVertices-1]=drawWidth-1; // bounds for random vertical offset from initial y value in zigzag line int vertBound = 45; //set y position of vertices //loop through all zigzag lines for(int iy = 0; iy < numLines; iy++) { // loop through all vertical grid lines for(int ix = 0; ix < numVertices; ix++) { if(iy==0) { y[ix][iy] = 0; } else if(iy==numLines-1) { y[ix][iy] = drawHeight; } else { y[ix][iy] = ((drawHeight/(numLines-1))*iy) + random((((drawHeight/(numLines-1))-vertBound)*-1), (drawHeight/(numLines-1))-vertBound); } } } } void draw() { background(255); //Draw top line line(0,0,drawWidth,0); line(0,1,drawWidth,1); //draw bottom line line(0,drawHeight,drawWidth,drawHeight); line(0,drawHeight-1,drawWidth,drawHeight-1); line(0,drawHeight-2,drawWidth,drawHeight-2); //draw left line line(0,0,0,drawHeight); line(1,0,1,drawHeight); //draw right line line(drawWidth,0,drawWidth,drawHeight); line(drawWidth-1,0,drawWidth-1,drawHeight); line(drawWidth-2,0,drawWidth-2,drawHeight); // Draw all the zigzag lines //loop through all horizontal grid lines for(int iy = 1; iy < numLines; iy++) { // loop through all vertical grid lines for(int ix = 1; ix < numVertices; ix++) { //draw all the zig zag lines line(x[ix-1],y[ix-1][iy], x[ix],y[ix][iy]); } } //loop through all horizontal grid lines for(int iy = 1; iy < numLines; iy++) { // loop through all vertical grid lines for(int ix = 1; ix < numVertices; ix++) { //Draw the quadrilateral fills (this determines chance of getting any particular fill) int fillPick = int(random(0,12)); // if fillPick is 0 do nothing // if fillPick is 1 then draw triangles if((fillPick < 3) && filled[ix][iy]==false) { // whether to put the point of the triangle on the to or bottom of the quadrilateral int dirPick = int(random(1,3)); // declare slope and intercept variables for bottom and top of quadrilateral float slope1=0; float intercept1=0; float slope2=0; float intercept2=0; // if dirPick is 1 then put the point of the triangle at the top if(dirPick==1) { // the slope of the top bound of the current quadrilateral slope1 = (y[ix-1][iy-1]- y[ix][iy-1])/(x[ix-1]-x[ix]); // the y intercept of the top bound intercept1 = y[ix-1][iy-1] - (slope1*x[ix-1]); // the slope of the bottom bound of the current quadrilateral slope2 = (y[ix-1][iy]- y[ix][iy])/(x[ix-1]-x[ix]); // the y intercept of the bottom bound of the current quadrilateral intercept2 = y[ix-1][iy] - (slope2*x[ix-1]); } // otherwise put the point at the bottom else { // the slope of the top bound of the current quadrilateral slope2 = (y[ix-1][iy-1]- y[ix][iy-1])/(x[ix-1]-x[ix]); // the y intercept of the top bound intercept2 = y[ix-1][iy-1] - (slope2*x[ix-1]); // the slope of the bottom bound of the current quadrilateral slope1 = (y[ix-1][iy]- y[ix][iy])/(x[ix-1]-x[ix]); // the y intercept of the bottom bound of the current quadrilateral intercept1 = y[ix-1][iy] - (slope1*x[ix-1]); } // the number of triangles to draw float numTriangles = random(5, 10); // loop through the number of triangles for(int i=0; i 2 && fillPick < 6) && filled[ix][iy]==false) { // the slope of the top bound of the current quadrilateral float slope1 = (y[ix-1][iy-1]- y[ix][iy-1])/(x[ix-1]-x[ix]); // the y intercept of the top bound float intercept1 = y[ix-1][iy-1] - (slope1*x[ix-1]); // the slope of the bottom bound of the current quadrilateral float slope2 = (y[ix-1][iy]- y[ix][iy])/(x[ix-1]-x[ix]); // the y intercept of the bottom bound of the current quadrilateral float intercept2 = y[ix-1][iy] - (slope2*x[ix-1]); // the number of lines to draw float numLines = random(5, 15); // loop through the number of lines for(int i=0; i<numLines; i++) { // get a random x in the current quadrilateral float randomX1 = random(x[ix-1],x[ix]); // get a random y based on the random x (so that it falls on one of the quadrilateral bounding lines) float randomY1 = (slope1*randomX1)+intercept1; // get a random y based on the random x (so that it falls on one of the quadrilateral bounding lines) float randomY2 = (slope2*randomX1)+intercept2; // draw a lines to from the top to the bottom bounding lines line(randomX1, randomY1, randomX1, randomY2); } } // if fillPick is 3 then draw straight lines down an extra row else if(fillPick == 6 && iy < numLines-1 && filled[ix][iy]==false) { // the slope of the top bound of the current quadrilateral float slope1 = (y[ix-1][iy-1]- y[ix][iy-1])/(x[ix-1]-x[ix]); // the y intercept of the top bound float intercept1 = y[ix-1][iy-1] - (slope1*x[ix-1]); // the slope of the bottom bound of the current quadrilateral float slope2 = (y[ix-1][iy+1]- y[ix][iy+1])/(x[ix-1]-x[ix]); // the y intercept of the bottom bound of the current quadrilateral float intercept2 = y[ix-1][iy+1] - (slope2*x[ix-1]); // the number of lines to draw float numLines = random(5, 15); // loop through the number of lines for(int i=0; i<numLines; i++) { // get a random x in the current quadrilateral float randomX1 = random(x[ix-1],x[ix]); // get a random y based on the random x (so that it falls on one of the quadrilateral bounding lines) float randomY1 = (slope1*randomX1)+intercept1; // get a random y based on the random x (so that it falls on one of the quadrilateral bounding lines) float randomY2 = (slope2*randomX1)+intercept2; // draw a lines to from the top to the bottom bounding lines line(randomX1, randomY1, randomX1, randomY2); } // set the lower quadrilateral to filled filled[ix][iy+1] = true; } } } // Draw the circles for (int i = 0; i < numCircles; i++) { // get a circle with a random circumference float circum = random(4, 100); // get the circle's radius float circRad = circum/2; // get the minimum x and y postion that would keep the circle in frame float minPos = 0+circRad; // get the maximum x and y position that would keep the circle in frame float maxPos = drawHeight-circRad; // draw the random circle ellipse(random(minPos, maxPos), random(minPos, maxPos), circum, circum); } delay(2500); } |
Comments Off on EliRosen – 13-9-65