diff --git a/Implementierung/tricorn.c b/Implementierung/tricorn.c index fa5975e..dfc25e1 100644 --- a/Implementierung/tricorn.c +++ b/Implementierung/tricorn.c @@ -133,6 +133,7 @@ void tricorn(float complex start, size_t width, ssize_t height, float res, unsig } } +// Iterative application of the equation given by the assignment static unsigned converge(float c_real, float c_imag, unsigned n) { float real = 0.0f; float imag = 0.0f; @@ -141,10 +142,12 @@ static unsigned converge(float c_real, float c_imag, unsigned n) { float real2 = real * real; float imag2 = imag * imag; + // If the pixel has diverged calculate the value and return it if (real2 + imag2 > 4.0f) { return 255 - 4 * (i % 64); } + // Calculate imaginary and real parts separately imag = -2.0f * real * imag + c_imag; real = real2 - imag2 + c_real; } diff --git a/Implementierung/tricorn_V1.c b/Implementierung/tricorn_V1.c index 8996935..3787dbc 100644 --- a/Implementierung/tricorn_V1.c +++ b/Implementierung/tricorn_V1.c @@ -28,19 +28,15 @@ void tricorn_V1(float complex start, size_t width, ssize_t height, float res, un float vertical_step = imag_direction * res; - size_t position = 0; + size_t position = 0; // Start value for the position in the image buffer. Will be accumulated later - float c_imag = c_start_imag; - // Simple iteration over every pixel in the picture + float c_imag = c_start_imag; // Start value for the imaginary part, which will be accumulated for(ssize_t y = 0; y < actual_height; y++){ - // Calculate imaginary part on each row as it stays the same float c_real = c_start_real; for(size_t x = 0; x < width; x++){ unsigned value = converge(c_real,c_imag,n); - // Pixel value position in the output array - if(!color){ // Grayscale colors as specified by the assignment r = g = b img[position] = value; } @@ -50,11 +46,10 @@ void tricorn_V1(float complex start, size_t width, ssize_t height, float res, un img[position + 2] = color_lookup_table[value][2]; } - position += bytesPerColor; - c_real += res; - + position += bytesPerColor; // Caculate position for next pixel + c_real += res; // Calculate real part for next pixel } - c_imag += vertical_step; + c_imag += vertical_step; // For reach row calculate the next value for the imaginary part by accumulation } } @@ -67,10 +62,12 @@ static inline unsigned converge(float c_real, float c_imag, unsigned n) { float real2 = real * real; float imag2 = imag * imag; + // If the pixel has diverged calculate the value and return it if (real2 + imag2 > 4.0f) { return 255 - 4 * (i % 64); } - + + // Calculate imaginary and real parts separately imag = -2.0f * real * imag + c_imag; real = real2 - imag2 + c_real; } diff --git a/Implementierung/tricorn_V2.c b/Implementierung/tricorn_V2.c index 352e7b3..3754eb4 100644 --- a/Implementierung/tricorn_V2.c +++ b/Implementierung/tricorn_V2.c @@ -130,6 +130,7 @@ void tricorn_V2(float complex start, size_t width, ssize_t height, float res, un } } +// Iterative application of the equation given by the assignment static unsigned converge(float c_real, float c_imag, unsigned n) { float real = 0.0f; float imag = 0.0f; @@ -138,10 +139,12 @@ static unsigned converge(float c_real, float c_imag, unsigned n) { float real2 = real * real; float imag2 = imag * imag; + // If the pixel has diverged calculate the value and return it if (real2 + imag2 > 4.0f) { return 255 - 4 * (i % 64); } - + + // Calculate imaginary and real parts separately imag = -2.0f * real * imag + c_imag; real = real2 - imag2 + c_real; } diff --git a/Implementierung/tricorn_V3.c b/Implementierung/tricorn_V3.c index 8c52fa5..3853701 100644 --- a/Implementierung/tricorn_V3.c +++ b/Implementierung/tricorn_V3.c @@ -212,10 +212,12 @@ static unsigned converge(float c_real, float c_imag, unsigned n) { float real2 = real * real; float imag2 = imag * imag; + // If the pixel has diverged calculate the value and return it if (real2 + imag2 > 4.0f) { return 255 - 4 * (i % 64); } + // Calculate imaginary and real parts separately imag = -2.0f * real * imag + c_imag; real = real2 - imag2 + c_real; }