// Dartmouth CS 2, Winter 2009, Chris Bailey-Kellogg // Notes 1 | Sketch 6 // 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 frameRate(15); // Slow it down -- 15 frames per second } // What to do every frame void draw() { if (mousePressed) { // Choose random red, green, and blue components of the stroke color // Also make it slightly opaque (200) stroke(random(255),random(255),random(255),200); // Choose random width of the stroke strokeWeight(random(30)); // Now draw a line from the current mouse position to the previous one line(mouseX,mouseY,pmouseX,pmouseY); // Remember this line x = mouseX; y = mouseY; dx = mouseX-pmouseX; dy = mouseY-pmouseY; strength = 1.0; lastLineFrame = frameCount; } else { if (frameCount - lastLineFrame > 35) { // Start a new random computer-drawn line x = random(width); y = random(height); dx = random(-8,8); dy = random(-8,8); strength = 1.0; lastLineFrame = frameCount; } if (strength > 0.01) { // Continue a decaying line kind of along the same direction float x2 = x, y2 = y; x = x+random(3*dx); y = y+random(3*dy); // Random color and weight like before; note that opacity is a function of strength stroke(random(255),random(255),random(255),200*strength); strokeWeight(random(30)); line(x,y,x2,y2); // Decay strength = strength * 0.9; } } // Every fifth frame, draw a square if (frameCount % 5 == 0) { // Random fill color; somewhat more opaque noStroke(); fill(random(0,60),random(30,80),random(80,120),100); // Random position; size 100x100 rect(random(width),random(height), 100,100); } }