/* 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; int offset = height; boolean offsetDirection = true; 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() { if (offsetDirection) { offset--; } else { offset++; } if (offset == 0 || offset == height) { offsetDirection = !offsetDirection; } 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; inversion(); } float random_coord() { if (random(1) > 0.7) { return random(3) * -1; } else { return random(3); } } // This is modified code from here: http://incubator.quasimondo.com/processing/inversion.pde void inversion() { int i = 0, d, xn, yn, dx, dy; boolean mx, my; int xc = offset; int yc = offset; int k = offset * 250; for (int y = 0; y < height; y++) { dy = y - yc; for (int x = 0; x < width; x++) { dx = x - xc; d = dx * dx + dy * dy; if (d > 0) { xn = xc + (k * dx) / d; yn = yc + (k * dy) / d; } else { xn=xc; yn=yc; } mx = false; while (xn < 0) { xn+=width; mx=!mx; } while ( xn >= width) { xn -= width; mx = !mx; } my = false; while (yn < 0) { yn += height; my = !my; } while (yn >= height) { yn -= height; my = !my; } if (mx) { xn = width - 1 - xn; } if (my) { yn = height - 1 -yn; } pixels[i++] = pixels[xn + yn * width]; } } }