// Based on code 43-02 (p. 409) ////////////////////////////////////////////////////// modification for forkable.eu import processing.pdf.*; String outputdir = "tmp/"; /////////////////////////////////////////////////////////////////////////////////// Ring[] rings; // Declare the array int numRings = 50; int currentRing = 0; boolean record = false; void setup() { size(513, 666); smooth(); rings = new Ring[numRings]; // Construct the array for (int i = 0; i < numRings; i++) { rings[i] = new Ring(); // Construct each object } } void draw() { if(frameCount%int(random(100,400)) == 0) { record = true; } if(frameCount%50 == 0) { createRing(random(0,height),random(width/4,width/2)); } if(record) { //beginRecord(PDF, "page_394-alt.pdf"); // modification for forkable.eu beginRecord(PDF, outputdir + "page_394.pdf"); // modification for forkable.eu record = true; } background(255); for (int i = 0; i < numRings; i++) { rings[i].grow(); rings[i].display(); } if(record) { endRecord(); record = false; exit(); // modification for forkable.eu } } void keyPressed() { record = true; } ////////////////////////////////////////////////////// modification for forkable.eu // Click to create a new Ring /* void mousePressed() { rings[currentRing].start(mouseX, mouseY); currentRing++; if (currentRing >= numRings) { currentRing = 0; } } */ /////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////// modification for forkable.eu void createRing(float X, float Y) { rings[currentRing].start(X,Y); currentRing++; if (currentRing >= numRings) { currentRing = 0; } } /////////////////////////////////////////////////////////////////////////////////// class Ring { float x, y; // X-coordinate, y-coordinate float diameter; // Diameter of the ring boolean on = false; // Turns the display on and off void start(float xpos, float ypos) { x = xpos; y = ypos; on = true; diameter = 1; } void grow() { if (on == true) { diameter += 0.5; if (diameter > height*2) { on = false; } } } void display() { if (on == true) { noFill(); //strokeWeight(1); // modification for forkable.eu strokeWeight(4); // modification for forkable.eu //stroke(102, 153); // modification for forkable.eu stroke(0, 255); // modification for forkable.eu ellipse(x, y, diameter, diameter); } } }