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