From 1fade8b25033bc1c273326224c576e89c0e8f14c Mon Sep 17 00:00:00 2001 From: josh Date: Sun, 7 Dec 2008 22:18:36 +0000 Subject: [PATCH] added FatouComputation git-svn-id: svn://anubis/gvsu@321 45c1a28c-8058-47b2-ae61-ca45b979098e --- cs677/final/FatouComputation.cc | 25 +++++++++++++++++++++++++ cs677/final/FatouComputation.h | 13 +++++++++++++ cs677/final/Makefile | 1 + cs677/final/mpi-fractals.cc | 10 ++++++++++ 4 files changed, 49 insertions(+) create mode 100644 cs677/final/FatouComputation.cc create mode 100644 cs677/final/FatouComputation.h diff --git a/cs677/final/FatouComputation.cc b/cs677/final/FatouComputation.cc new file mode 100644 index 0000000..ca9b1ed --- /dev/null +++ b/cs677/final/FatouComputation.cc @@ -0,0 +1,25 @@ + +#include /* sqrt() */ +#include /* complex, I, creal(), cimag() */ +#include "FatouComputation.h" + +#define LEEWAY 0.001 +#define ITERATIONS 100 +#define CLOSE_ENOUGH(z, x, y) \ + (fabs(creal(z) - (x)) < LEEWAY && fabs(cimag(z) - (y)) < LEEWAY) + +unsigned int FatouComputation::compute(double x, double y) +{ + double complex z = 0.1; + double complex p = x + I * y; + + for (int iter = 0; iter < ITERATIONS; iter++) + { + z = p * (1 - z) * z; + if (cabs(z) > 2.0) + { + return 0xFF * ((double) iter / (double) ITERATIONS); + } + } + return 0; +} diff --git a/cs677/final/FatouComputation.h b/cs677/final/FatouComputation.h new file mode 100644 index 0000000..685e361 --- /dev/null +++ b/cs677/final/FatouComputation.h @@ -0,0 +1,13 @@ + +#ifndef FATOUCOMPUTATION_H +#define FATOUCOMPUTATION_H FATOUCOMPUTATION_H + +#include "Computation.h" + +class FatouComputation : public Computation +{ + public: + unsigned int compute(double x, double y); +}; + +#endif diff --git a/cs677/final/Makefile b/cs677/final/Makefile index a0f34f2..ee659c7 100644 --- a/cs677/final/Makefile +++ b/cs677/final/Makefile @@ -5,6 +5,7 @@ LDFLAGS := `sdl-config --libs` TARGET := mpi-fractals OBJS := mpi-fractals.o OBJS += NewtonComputation.o +OBJS += FatouComputation.o all: $(TARGET) diff --git a/cs677/final/mpi-fractals.cc b/cs677/final/mpi-fractals.cc index 540ee21..2902f58 100644 --- a/cs677/final/mpi-fractals.cc +++ b/cs677/final/mpi-fractals.cc @@ -9,6 +9,7 @@ #include #include "Computation.h" #include "NewtonComputation.h" +#include "FatouComputation.h" using namespace std; /* a "task" will be processing TASK_SIZE pixels */ @@ -63,6 +64,15 @@ int main(int argc, char * argv[]) case 0: default: computation = new NewtonComputation(); + x_center = 0.0; + y_center = 0.0; + zoom = 2.0 / width; + break; + case 1: + computation = new FatouComputation(); + x_center = 3.001; + y_center = 0.075975; + zoom = 2.0 / width; break; }