Commit 653cc12a authored by Andreas Kempe's avatar Andreas Kempe

Modified the mandelbrot colouring.

parent fa94b49b
......@@ -20,7 +20,7 @@ using namespace Magick;
struct MandelResult
{
unsigned long end_iterations;
float 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
for (unsigned long i = 0; i < iterations; ++i)
{
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;
}
......@@ -60,8 +60,8 @@ int main(int argc, char** argv)
{
int id;
int procs;
unsigned long *calculated_values;
unsigned long *receive_buffer = nullptr;
float *calculated_values;
float *receive_buffer = nullptr;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &procs);
......@@ -73,7 +73,7 @@ int main(int argc, char** argv)
// Calculate this threads working area.
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)
{
......@@ -86,17 +86,17 @@ int main(int argc, char** argv)
}
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;
MPI_Gather(calculated_values, IMG_WIDTH * effective_height, MPI_UNSIGNED_LONG, receive_buffer,
IMG_WIDTH * effective_height, MPI_UNSIGNED_LONG, 0, MPI_COMM_WORLD);
MPI_Gather(calculated_values, IMG_WIDTH * effective_height, MPI_FLOAT, receive_buffer,
IMG_WIDTH * effective_height, MPI_FLOAT, 0, MPI_COMM_WORLD);
cout << "Process: " << id << ", done gathering!" << endl;
if (id == 0)
{
Image my_image(Geometry(IMG_WIDTH, IMG_WIDTH), "white");
Image my_image(Geometry(IMG_WIDTH, IMG_HEIGHT), "white");
my_image.modifyImage();
Pixels pixel_cache(my_image);
......@@ -121,9 +121,9 @@ int main(int argc, char** argv)
{
int iter_res = receive_buffer[y * IMG_WIDTH + x];
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
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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment