/* * Copyright (c) 2008 Carlos Rodrigues * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ class Point { int x = -1; int y = -1; } Point[] points = new Point[25]; int index = 0; void setup() { size(530, 250); frameRate(30); noCursor(); smooth(); for (int i = 0; i < points.length; i++) { points[i] = new Point(); } /* The initial background must be white to avoid a gray "splash"... */ background(255); } void draw() { /* Get a new point every other frame, except the first... */ if (frameCount % 2 == 0 && mouseX > 0 && mouseY > 0) { points[index % points.length].x = mouseX; points[index % points.length].y = mouseY; index++; } /* Paint the screen with transparency (blur)... */ noStroke(); fill(255, 160); rect(0, 0, width, height); stroke(0); noFill(); /* Draw the curves (the first and last points are control points)... */ beginShape(); for (int i = index; i < index + points.length; i++) { Point p = points[i % points.length]; if (p.x < 0 || p.y < 0) { continue; } curveVertex(p.x + random(-5,5), p.y + random(-5,5)); } endShape(); } void keyPressed() { if (key == ' ') { /* Mark all points as uninitialized, which will clear the screen... */ for (int i = 0; i < points.length; i++) { points[i].x = points[i].y = -1; } } } /* EOF - NervousLines.pde */