/* * Implementation of Clifford attractors. * * Based on http://www.bairdy.com/processing/strangeattractor/ and http://local.wasp.uwa.edu.au/~pbourke/fractals/clifford/ */ float A, B, C, D, DA, DB, DC, DD; float px = 0, py = 0; float W2, H2, W4, H4; void setup() { size(600, 600); frameRate(20); W2 = width / 2; H2 = height / 2; W4 = width / 4; H4 = height / 4; background(0); loadPixels(); mousePressed(); } void mousePressed() { int dna = int(1e8 * noise(frameCount + millis())); randomSeed(dna); do { A = random(-2, 2); } while (A == 0.0); do { B = random(-2, 2); } while (B == 0.0); do { C = random(-2, 2); } while (C == 0.0); do { D = random(-2, 2); } while (D == 0.0); DA = random(-0.05, 0.05); DB = random(-0.05, 0.05); DC = random(-0.05, 0.05); DD = random(-0.05, 0.05); px = 0; py = 0; for (int i = 0; i < pixels.length; i++) pixels[i] = color(0); updatePixels(); status("New DNA: " + dna); } void draw() { for (int i = 0; i < 10000; i++) { float x = sin(A * py) + C * cos(A * px), y = sin(B * px) + D * cos(B * py); int rx = int(W2 + W4 * x), ry = int(H2 + H4 * y); if (rx >= 0 && rx < width && ry >= 0 && ry < height) { int idx = rx + ry * width, g = int(red(pixels[idx])) + 10; pixels[idx] = color(g > 255 ? 255 : g); } px = x; py = y; } updatePixels(); float n = noise(frameCount); A += DA * n; B += DB * n; C += DC * n; D += DD * n; }