#include "pngwriter.h" #include #include #include #include #include #include #include #include #include #include "Mandel.h" /* * Written by Mike Rollins * rollins@alumni.wfu.edu * Copyright 2004. */ using namespace std; int main(int argc, char *argv[]) { char *mandel_version = "Version 1.0"; // record argv[1] as a string // if present char *power_string = NULL; if (argc == 2) { power_string = argv[1]; } // Set the width and the height // of the png image int width = 300; int height = 300; // set the parameters for the // calculation area float x_min = -2.5; float x_max = 2.5; float y_min = -1.5; float y_max = 1.5; // x_value and y_value will be used to record // the points to be tested. These values // will be calcuated by converting x and y values // for the pixel location into the x,y coordinate // values. x_slope and y_slope will be used for // this transformation float x_value = 0; float y_value = 0; float x_slope = ((float)(x_max - x_min))/((float)width); float y_slope = ((float)(y_max - y_min))/((float)height); int color_value = 65535; // used for the convergent points float ratio = 0; // stores the ration of convergence float power = 2.02; // default power // create a mandelbrot set calculation object Mandel M; M.set_max_iterations(100); // Print version information printf("%s\n",mandel_version); printf("%s\n",M.version()); // if the parameter for power is present // set the power to this value if (power_string) { power = atof(power_string); } printf("power = %f\n",power); // display the power being used M.set_power(power); // create a pngwriter object pngwriter image(width,height,0,"mandel.png"); // initialize the values for a progress meter int progress_points = 20; // create number of output statements int progress_mod = width/progress_points; // traverse the x points for (int x=0; x<=width; x++) { // display progress meter if (!(x % progress_mod)) { printf("%3.0f%\n",100.0 * float(x)/float(width)); } // traverse the y points for (int y=0; y<=height; y++) { // transform the x and y to numerical values for computation // x: 0 -> x_min, width -> x_max // y: 0 -> y_min, width -> y_max x_value = ((float)x)*x_slope+x_min; y_value = ((float)y)*y_slope+y_min; // set the point to be tested M.set_xy(x_value,y_value); M.calculate(); // test the point ratio = M.get_ratio(); //return the ratio if (ratio == 0) { // point is within the set image.plot(x,y,color_value,color_value,color_value); } else { // point is outside the set image.plotHSV(x,y,(double)0.656-(0.656* ratio),(double)(0.7)*(1.0 - ratio),1.0); } } } image.setgamma(0.7); image.close(); return 0; }