no need for the line-wise function anymore
This commit is contained in:
parent
bbae44fec7
commit
0c634fa609
1 changed files with 38 additions and 43 deletions
|
@ -44,40 +44,6 @@ pixel_t incolor() {
|
|||
return 0x00000000; /* black */
|
||||
}
|
||||
|
||||
/* Computes the visual representation of a mandelbrot set for a given line. */
|
||||
void compmandelbrot_line(bitmap_t * mbrot, size_t y) {
|
||||
|
||||
for (size_t x = 0; x < mbrot->width; x++) {
|
||||
|
||||
float complex c = ((3.0f * x / mbrot->width) - 2.0f)
|
||||
+ I * ((2.0f * y / mbrot->height) - 1.0f);
|
||||
|
||||
bool diverges = false;
|
||||
float complex z = 0;
|
||||
|
||||
int it;
|
||||
for (it = 1; it <= max_it; it++) {
|
||||
/* z = z² + c */
|
||||
z = cpowf(z, 2) + c;
|
||||
|
||||
/* If |z| ever gets greater than 2, it diverges. */
|
||||
if (cabsf(z) > 2) {
|
||||
diverges = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t color;
|
||||
if (diverges) {
|
||||
color = outcolor(it);
|
||||
} else {
|
||||
color = incolor();
|
||||
}
|
||||
|
||||
size_t i = y * mbrot->width + x;
|
||||
mbrot->pixels[i] = color;
|
||||
}
|
||||
}
|
||||
|
||||
/* Mandelbrot bitmap. */
|
||||
bitmap_t *mbrot;
|
||||
|
@ -129,13 +95,13 @@ static int save_png_to_file(bitmap_t * bitmap, const char *path) {
|
|||
|
||||
/* Set image attributes. */
|
||||
png_set_IHDR(png_ptr,
|
||||
info_ptr,
|
||||
bitmap->width,
|
||||
bitmap->height,
|
||||
depth,
|
||||
PNG_COLOR_TYPE_RGB,
|
||||
PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||
info_ptr,
|
||||
bitmap->width,
|
||||
bitmap->height,
|
||||
depth,
|
||||
PNG_COLOR_TYPE_RGB,
|
||||
PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||
|
||||
/* Initialize rows of PNG. */
|
||||
row_pointers = png_malloc(png_ptr, bitmap->height * sizeof(png_byte *));
|
||||
|
@ -184,9 +150,38 @@ int main() {
|
|||
assert(mbrot->pixels != NULL);
|
||||
|
||||
/* Compute. */
|
||||
#pragma omp parallel for
|
||||
#pragma omp parallel for schedule (dynamic, 50000)
|
||||
for (unsigned int y = 0; y < mbrot->height; y++) {
|
||||
compmandelbrot_line(mbrot, y);
|
||||
for (size_t x = 0; x < mbrot->width; x++) {
|
||||
|
||||
float complex c = ((3.0f * x / mbrot->width) - 2.0f)
|
||||
+ I * ((2.0f * y / mbrot->height) - 1.0f);
|
||||
|
||||
bool diverges = false;
|
||||
float complex z = 0;
|
||||
|
||||
int it;
|
||||
for (it = 1; it <= max_it; it++) {
|
||||
/* z = z² + c */
|
||||
z = cpowf(z, 2) + c;
|
||||
|
||||
/* If |z| ever gets greater than 2, it diverges. */
|
||||
if (cabsf(z) > 2) {
|
||||
diverges = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t color;
|
||||
if (diverges) {
|
||||
color = outcolor(it);
|
||||
} else {
|
||||
color = incolor();
|
||||
}
|
||||
|
||||
size_t i = y * mbrot->width + x;
|
||||
mbrot->pixels[i] = color;
|
||||
}
|
||||
}
|
||||
|
||||
/* Save PNG. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue