/* Written by Alex Young Based on: http://en.wikipedia.org/wiki/Aurora_borealis http://astronomy.swin.edu.au/~pbourke/fractals/peterdejong/ */ int width = 400, height = 400; int iterations; int colour_rate = 10; int defaultHeight = 20; color defaultColour; color colour; float x, y, x2, y2, lineHeight = 0; int px, py; float a, b, c, d; void setup() { defaultColour = color(100, 100, 140); iterations = 10000; x = 0; y = 0; x2 = 0; y2 = 0; lineHeight = 0; 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 (int f = 0; f < 14; f++) { if (mousePressed == true) { setup(); } if (iterations > 0) { if (int(lineHeight) < 1) { lineHeight = defaultHeight; } iterations--; 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); for (int i = 0; i < int(lineHeight); i++) { set(px, py + i, colour); colour = color(red(colour) + (i / 2), green(colour) + (i / 2), blue(colour) + (i / 2)); } lineHeight -= 0.1; x = x2; y = y2; } } } float random_coord() { if (random(1) > 0.7) { return random(3) * -1; } else { return random(3); } }