#include #include #include /* Standart Library of Complex Numbers */ int main() { // C also provides a Complex type which we can use (instead of two functions) // This type is use in the code below double complex z; // Initial c. double complex c = -0.4 + 0.6i; int i, j, k; double itr = 5000; double N = 5000; double range = 2; FILE * resultsFile = fopen( "results.csv", "wt" ); // Move along the column of points (trying to create a Lattice we can plot) for ( i = 0; i < itr; i++ ) { // Move along the row of points for ( j = 0; j < itr; j++ ) { z = (double)i/itr*range*2 - range + ( (double)j/itr * range * 2 - range ) * I; k = 0; // Iterate until z > N or we have taken up too many points. // Using k++ will also increment k by one each time we do the comparisison while( cabs( z ) < N && k++ < 255 ) { z = z * z + c; } // Write out a matrix of points, this is writing out each row fprintf( resultsFile, "%d ", k ); } // Move on to the next row. fprintf( resultsFile, "\n"); } fclose( resultsFile ); return 0; }