#include #include #include "Mandel.h" #include "Complx.h" /* * Written by Mike Rollins * rollins@alumni.wfu.edu * Copyright 2004. */ // set the power to p void Mandel::set_power(float p ) { this->p = p; } // set the max iterations void Mandel::set_max_iterations(int r ) { max_iterations = r; } // return the ration float Mandel::get_ratio() { if (converge) { return 0; } else { return ratio; } } // initialize the point (x,y) void Mandel::set_xy(float x, float y) { this->x = x; this->y = y; } void Mandel::calculate() { /************************ z0 is in point in plane z1 = z0^2 + z0 z2 = z1^2 + z0 z3 = z2^2 + z0 z4 = z3^2 + z0 **************************/ // initialize z Complx z(x,y); z.set_power(p); // initialize c to store // intermediate results Complx c(x,y); converge = 1; iteration_count = 0; do { z.raise_to_power(); // z0^2 z.Add(c); // z0^2+z0; // Convergence test converge= (abs((int)z.get_real()) < 2) && (abs((int)z.get_imaginary())<2) ; ++iteration_count; // Count iterations } while (converge && (iteration_count<=max_iterations)); // set the ratio ratio = ((float)iteration_count)/((float)(max_iterations+1)); } char *Mandel::version() { Complx z(1.0,1.0); strcpy(version_string,mandel_version); strcat(version_string,", "); strcat(version_string,z.version()); return version_string; };