/* ------------------------------------------------------------------------ MANDELBROT FRACTAL ------------------------------------------------------------------------ */ template <class numbertype> class mandelbrot { protected:
double bout; // bailout - stop if dist of z to origin greater bout long maxit; // max iteration - stop if iterations >= maxit
public:
// create default / with special bailout and max. iterations mandelbrot (void) { bout = 2.0; maxit = 50; } mandelbrot (double bailout, long maxiter) { bout = bailout; maxit = maxiter;}
// set bailout / max. iterations void set (double bailout, long maxiter) { bout = bailout; maxit = maxiter; }
// get bailout / max. iterations double bailout (void) const { return (bout); } long maxiter (void) const { return (maxit); }
// eval point c (return number of steps) virtual long eval (const numbertype &c) const { numbertype z; return (eval(c,z,0)); } // is point c part of mandelbrot set (eval >= max.iterations) virtual bool partof (const numbertype &c) const { return ((eval(c)>=maxit)); } protected:
virtual long eval (const numbertype &c, const numbertype &z, long n) const { numbertype zi (z); for ( ; n<maxit; zi = (zi*zi)+c, n++) if (zi.origin()>=bout) return (n); return (maxit); }
// rucursive version // virtual long eval (const numbertype &c, numbertype z, long n) { // if (n>=maxit || z.origin()>=bout) return(n); // else return( eval (c, (z*z)+c, n+1) ); }
};
/* ------------------------------------------------------------------------ JULIA FRACTAL ------------------------------------------------------------------------ */ template <class numbertype> class julia : public mandelbrot<numbertype> { protected: public:
// create default / with special bailout and max. iterations julia (void) { bout = 2.0; maxit = 50; } julia (double bailout, long maxiter) { bout = bailout; maxit = maxiter; }
// eval point z of mandelbrot point c (return number of steps) virtual long eval (const numbertype &c, const numbertype &z) const { return (mandelbrot<numbertype>::eval(c,z,0)); }
// is point z part of mandelbrot set (eval >= max.iterations) virtual int partof (const numbertype &c, const numbertype &z) const { return ((eval(c,z)>=maxit)); } };
|