some more comments
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user