I gave a presentation at yesterday’s DIT School of Mathematical Sciences lunchtime research seminar titled Ways of Seeing Julia Sets: Visualizing the forces that shape fractal Julia sets. This was the abstract:
My Prezi slides can be viewed here:
http://prezi.com/f5ymufi-bfqc/ways-of-seeing-julia-sets/
During my presentation, I demonstrated two short C programs that generated these fractal images.
This is the complete C code for the Mandelbrot example:
#include <stdio.h> #include <complex.h> void main() { complex double z, c; int x, y, i; printf("P2\n4000 4000\n255\n"); for (y=0 ; y<4000 ; ++y) { for (x=0 ; x<4000 ; ++x) { z = 0; c = (-2 + x*0.001) + (-2 + y*0.001)*I; i = 0; while (cabs(z) < 2 && ++i < 255) z = z*z + c; printf("%4d", i); } printf("\n"); } }
I compiled and ran the program as follows:
gcc mandelbrot.c -o mandelbrot -lm ./mandelbrot > mandelbrot.pgm
The C code for the Julia set example is almost identical except that it’s now z rather than c which changes from pixel to pixel (i.e. with changing x and y coordinates) and c is constant throughout the image (the value of c you choose determines which Julia set you end up with).
#include <stdio.h> #include <complex.h> void main() { complex double z, c; int x, y, i; printf("P2\n4000 4000\n255\n"); for (y=0 ; y<4000 ; ++y) { for (x=0 ; x<4000 ; ++x) { c = -0.625 - 0.4*I; z = (-2 + x*0.001) + (-2 + y*0.001)*I; i = 0; while (cabs(z) < 2 && ++i < 255) z = z*z + c; printf("%4d", i); } printf("\n"); } }
I compiled and ran the program as follows:
gcc julia.c -o julia -lm ./julia > julia.pgm