/* Written by Alex Young Based on: http://astronomy.swin.edu.au/~pbourke/fractals/peterdejong/ */ int width = 340, height = 340, intensity = 1700; float speed = 0.005; color col; float x = 0, y = 0, x2, y2; int px, py, iteration; float a, b, c, d; boolean increment = false; void setup() { colorMode(RGB, 255); size(width, height); background(0); a = random_coord(); b = random_coord(); c = random_coord(); d = random_coord(); col = color(int(random(240)), int(random(210)), int(random(240))); } void loop() { fill(color(0, 0, 0), 10); rect(0, 0, width, height); for (iteration = 0; iteration < intensity; iteration++) { if (mousePressed == true) { setup(); } x2 = cos(a * x) - sin(c * y); y2 = sin(b * x) - cos(d * y); // Convert to screen co-ords px = int((x2 + 1) * 80) + 80; py = int((y2 + 1) * 90) + 100; if (increment) { col += 0.5; } else { col -= 0.5; } set(px, py, col); x = x2; y = y2; } if (random(1) > 0.5) { increment = !increment; } a -= speed; b -= speed; c -= speed; d -= speed; } float random_coord() { if (random(1) > 0.7) { return random(3) * -1; } else { return random(3); } }