// Based on a sketch by Sharp Hall, http://stereotheism.org/071106/ // Stuff that needs to be remembered from one frame to the next float x, y; // The end of the line float dx, dy; // The length of the line float strength=0; // Computer-drawn lines decay and fade away int lastLineFrame=0; // When did the last computer-drawn line start? // Initialization void setup() { size(500,500); // Make the window bigger smooth(); // Make the edges smoother (anti-aliased) background(0,0,0); // Black background strokeWeight(2); // Thicken the lines drawn } // What to do every frame void draw() { if (mousePressed) { // set the strength to high strength = 1; // Choose random red, green, and blue components of the fill and stroke color // also make it a bit transparent fill(random(200,255),random(200,255),random(200,255),100); stroke(random(128,255),random(128,255),random(128,255),100); // pick a random radius and save it away float radius = random(50); // draw the ellipse ellipse(mouseX,mouseY,radius,radius); // draw a line connecting this position to the last one line(mouseX,mouseY,pmouseX,pmouseY); // Remember this stroke x = mouseX; y = mouseY; dx = mouseX-pmouseX; dy = mouseY-pmouseY; lastLineFrame = frameCount; } else { if (frameCount - lastLineFrame > 150) { // Start a new random computer-drawn line x = random(width); y = random(height); dx = random(-20,20); dy = random(-20,20); strength = 1.0; lastLineFrame = frameCount; } if (strength > 0.05) { // Continue a decaying line kind of along the same direction float x2 = x, y2 = y; x = x+random(dx); y = y+random(dy); // Random color and weight like before; note that opacity is a function of strength fill(random(200,255),random(200,255),random(200,255),100*strength); stroke(random(128,255),random(128,255),random(128,255),100*strength); // pick a random radius and save it away float radius = random(50); // draw the ellipse ellipse(x,y,radius,radius); // draw a line connecting this position to the last one line(x,y,x2,y2); // decrease the strength strength = strength * 0.95; } } // Every 30-th frame, draw a random ellipse if (frameCount % 45 == 0) { // Choose darker random colors fill(random(30,100),random(30,100),random(30,100),100); stroke(random(30,120),random(30,120),random(30,120),100); // pick a random radius and save it away float radius = random(100,200); // draw the ellipse at random position ellipse(random(width),random(height),radius,radius); } } // START NO NOTES // code used to capture screenshots void keyReleased() { if(key == '`') save("sketch.png"); }