/* Written by Alex Young Based on: http://astronomy.swin.edu.au/~pbourke/fractals/peterdejong/ */ int width = 400, height = 400; int iteration; int colourRate = 6; color defaultColour; color colour; float x = 0, y = 0, x2, y2; int px, py; float a, b, c, d; void setup() { defaultColour = color(100, 100, 140); size(width, height); colorMode(RGB, 255); stroke(defaultColour); // Make a nice gradient for (y = 0; y < height; y++) { stroke(red(defaultColour) - (y / 3), green(defaultColour) - (y / 3), blue(defaultColour) - (y / 3)); line(0, y, width, y); } a = random_coord(); b = random_coord(); c = random_coord(); d = random_coord(); } void loop() { for (iteration = 0; iteration < 150; 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) * 70) + 70; py = int((y2 + 1) * 70) + 70; // Get the colour of the pixel colour = get(px, py); colour = color(red(colour) + colourRate, green(colour) + colourRate, blue(colour) + colourRate); set(px, py, colour); x = x2; y = y2; } } float random_coord() { if (random(1) > 0.7) { return random(4) * -1; } else { return random(4); } }