Skip to content
Snippets Groups Projects
Commit 653cc12a authored by Andreas Kempe's avatar Andreas Kempe
Browse files

Modified the mandelbrot colouring.

parent fa94b49b
Branches
Tags
No related merge requests found
...@@ -20,7 +20,7 @@ using namespace Magick; ...@@ -20,7 +20,7 @@ using namespace Magick;
struct MandelResult struct MandelResult
{ {
unsigned long end_iterations; float end_iterations;
bool belongs; bool belongs;
MandelResult(unsigned long end_iterations, bool belongs) : MandelResult(unsigned long end_iterations, bool belongs) :
...@@ -48,7 +48,7 @@ MandelResult IsMandelbrotPoint(unsigned long x, unsigned long y, unsigned int it ...@@ -48,7 +48,7 @@ MandelResult IsMandelbrotPoint(unsigned long x, unsigned long y, unsigned int it
for (unsigned long i = 0; i < iterations; ++i) for (unsigned long i = 0; i < iterations; ++i)
{ {
if (real(series_value) * real(series_value) + imag(series_value) * imag(series_value) >= 4) if (real(series_value) * real(series_value) + imag(series_value) * imag(series_value) >= 4)
return MandelResult(abs(series_value), false); return MandelResult(i + 1 - log(log(abs(pow(series_value, 2) + point))) / log(2), false);
series_value= pow(series_value, 2) + point; series_value= pow(series_value, 2) + point;
} }
...@@ -60,8 +60,8 @@ int main(int argc, char** argv) ...@@ -60,8 +60,8 @@ int main(int argc, char** argv)
{ {
int id; int id;
int procs; int procs;
unsigned long *calculated_values; float *calculated_values;
unsigned long *receive_buffer = nullptr; float *receive_buffer = nullptr;
MPI_Init(&argc, &argv); MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &procs); MPI_Comm_size(MPI_COMM_WORLD, &procs);
...@@ -73,7 +73,7 @@ int main(int argc, char** argv) ...@@ -73,7 +73,7 @@ int main(int argc, char** argv)
// Calculate this threads working area. // Calculate this threads working area.
effective_height /= procs; effective_height /= procs;
calculated_values = new unsigned long[IMG_WIDTH * effective_height]; calculated_values = new float[IMG_WIDTH * effective_height];
for (unsigned long y = effective_height * id; y < effective_height * (id + 1); ++y) for (unsigned long y = effective_height * id; y < effective_height * (id + 1); ++y)
{ {
...@@ -86,17 +86,17 @@ int main(int argc, char** argv) ...@@ -86,17 +86,17 @@ int main(int argc, char** argv)
} }
if (id == 0) if (id == 0)
receive_buffer = new unsigned long[IMG_WIDTH * IMG_HEIGHT]; receive_buffer = new float[IMG_WIDTH * IMG_HEIGHT];
cout << "Process: " << id << ", Gathering!" << endl; cout << "Process: " << id << ", Gathering!" << endl;
MPI_Gather(calculated_values, IMG_WIDTH * effective_height, MPI_UNSIGNED_LONG, receive_buffer, MPI_Gather(calculated_values, IMG_WIDTH * effective_height, MPI_FLOAT, receive_buffer,
IMG_WIDTH * effective_height, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD); IMG_WIDTH * effective_height, MPI_FLOAT, 0, MPI_COMM_WORLD);
cout << "Process: " << id << ", done gathering!" << endl; cout << "Process: " << id << ", done gathering!" << endl;
if (id == 0) if (id == 0)
{ {
Image my_image(Geometry(IMG_WIDTH, IMG_WIDTH), "white"); Image my_image(Geometry(IMG_WIDTH, IMG_HEIGHT), "white");
my_image.modifyImage(); my_image.modifyImage();
Pixels pixel_cache(my_image); Pixels pixel_cache(my_image);
...@@ -121,9 +121,9 @@ int main(int argc, char** argv) ...@@ -121,9 +121,9 @@ int main(int argc, char** argv)
{ {
int iter_res = receive_buffer[y * IMG_WIDTH + x]; int iter_res = receive_buffer[y * IMG_WIDTH + x];
if (iter_res == ITERATIONS) if (iter_res == ITERATIONS)
pixels[y * IMG_WIDTH + x] = Color("purple"); pixels[y * IMG_WIDTH + x] = Color(MaxRGB * 0.55, MaxRGB * 0.35, MaxRGB * 0.6);
else else
pixels[y * IMG_WIDTH + x] = Color(0, 0, MaxRGB * static_cast<float>(iter_res) / max); pixels[y * IMG_WIDTH + x] = Color(MaxRGB * cosf(exp(iter_res)), 0, MaxRGB * sinf(exp(iter_res)));
} }
} }
pixel_cache.sync(); pixel_cache.sync();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment