Search
• Shyam Patel

# Book Brief - RandomBook - Coding Workshop 3

In this workshop, I was able to establish my level of independent learning based on the skills and knowledge I learned throughout the coding workshops with my lecturer Rob. The code below will de-construct particular lines that were discussed during the workshop and all annotations show that I clearly understand the code despite the complexity at times. All my comments will be in bold, the rest is regular weight. As a result of this code, the images below are a selection of some of the outcomes as a result of this modified code.

/**

* RandomBook

*

* Creates a 768 page book of random lines.

*/

import processing.pdf.*;

PGraphicsPDF pdf; // "PDF" is an instance (child) of the PGraphicsPDF class

void setup() {

size(594, 842); // A4

randomSeed(58); // Uncomment to make the same book each time

pdf = (PGraphicsPDF)beginRecord(PDF, "RandomBook12.pdf");

beginRecord(pdf);

}

int pageNumber = 7; // easier to access to number of pages rendered

void draw() {

background(255);

for (int i=0; i<100; i++) { // draw a defined number of random lines

float r = random(1.0); // floating point and this is going to generate lots of random points between 0 and 1

if(r < 0.2) { // set the ratio of black to white strokes / if "r" is less than 0.2 we set to stroke to 255 - 1 chance in 5 the stroke is going to be set to white and 4 chances out of 5 the stroke will be set to black

stroke(random(25,213),random(199,25),random(51,25)); // (white)

} else {

stroke(random(22,95),random(132,22),random(25,255)); // black

}

float sw = pow(random(1.0), 12); // pow creates value steps - which generates strokeweights

strokeWeight(sw * 260); // generate a random strokeweights - the multiplication factor is 12

// all lines originate and terminate outside the document bounds

float x1 = random(-200, -100); // its going to be a random number between -200 and -100 - which is outside the document

float x2 = random(width+100, width+200); //

float y1 = random(-100, height+100); // the height of the document plus 100

float y2 = random(-100, height+100);

line(x1, y1, x2, y2); //

}

if(frameCount == 77) { // the draw function will operate unless told otherwise and loop as fast as it can. What can be done is the frame rate can be invoked in the setup and that will tell processing that if possible it loops the draw function 30 times a second.

endRecord();

exit(); // Quit

} else {

pdf.nextPage(); // Tell it to go to the next page

}

}

6 views

See All