/** study in trig-powered lines, by Josh Giesbrecht */ float x, y, radius; float angleA, angleB; float xmin, xmax, ymin, ymax; int resetcount = 0; float centerX; float centerY; void setup() { size(400,400); background(0); //smooth(); centerX = width * 0.66; centerY = height * 0.33; reset(); frameRate(200); } void draw() { // the "max" value is always a larger absolute value than // min, but if max is negative then it's smaller than min and // we need to swap how we pass them to random() if (xmin < xmax) { x += random(xmin, xmax); } else { x += random(xmax, xmin); } if (ymin < ymax) { y += random(ymin, ymax); } else { y += random(ymax, ymin); } radius -= 0.1; angleA += PI/20; angleB += PI/20; drawline(); if (radius < 1 || x > width*1.2 || x < width*-0.2 || y > height * 1.2 || y < height * -0.2 ) { reset(); } } void reset() { resetcount++; if (resetcount > 200) { print("Done."); exit(); } x = random(0,400); y = random(0,400); float xbase = x - centerX; float ybase = y - centerY; xmax = xbase/100; xmin = xmax*-1/2; ymax = ybase/100; ymin = ymax*-1/2; radius = 5 + dist(x, y, centerX, centerY) / 10; angleA = 0; angleB = PI/2; stroke(pickcolor()); } color pickcolor() { int rand = (int)random(0,10); if (rand < 2) { return color(160,160,100,64); } else if (rand < 5) { return color(100,100,255,64); } else if (rand < 8) { return color(255,255,255,50); } else { return color(110,100,100,64); } } void drawline() { float ax = x + cos(angleA)*radius; float ay = y + sin(angleA)*radius; float bx = x + cos(angleB)*radius; float by = y + sin(angleB)*radius; line(ax, ay, bx, by); //point(x, y); }