/* * * */ #include #include #include #include #include "mandelbrot.h" #define MAX_ESCAPESTEPS 256 int main (int argc, char *argv[]) { double xcentre = 0; double ycentre = 0; int z = 8; double pixeldistance = pow(2, -z); // start from the top left of the region double firstX = (xcentre - 256); //* pixeldistance; double lastX = (xcentre + 256); double firstY = (ycentre + 256); double lastY = (ycentre - 256); double middleX = (firstX + lastX); double middleY = (firstY + lastY); printf("midpoint: (%lf,%lf)\n", middleX, middleY); printf("firstX = %lf\n", firstX); printf("lastX = %lf\n", lastX); printf("firstY = %lf\n", firstY); printf("lastY = %lf\n", lastY); int x; for (x = -256; x <= 256; x++) { double y; // printf("%i\n", escapeSteps(x, y)); for (y = -256*pixeldistance; y <= 256*pixeldistance; y+=pixeldistance) { printf("(%f,%f)", x, y); // printf("%i\n", escapeSteps(x, y)); if (escapeSteps(x, y) < MAX_ESCAPESTEPS) { printf("*"); } else { printf(" "); } } printf("\n"); } return EXIT_SUCCESS; } int escapeSteps (double x, double y) { int steps = 0; double real = 0; double imaginary = 0; double modSquared = ((real * real) + (imaginary * imaginary)); double newImaginary; double newReal; while (modSquared < 4 && steps < MAX_ESCAPESTEPS) { newImaginary = (2 * imaginary * real)+y; newReal = ((real * real) - (imaginary * imaginary))+x; imaginary = newImaginary; real = newReal; modSquared = ((newReal * newReal) + (newImaginary * newImaginary)); steps++; } return steps; }