no need for the line-wise function anymore

master
neingeist 11 years ago
parent bbae44fec7
commit 0c634fa609

@ -44,40 +44,6 @@ pixel_t incolor() {
return 0x00000000; /* black */ 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. */ /* Mandelbrot bitmap. */
bitmap_t *mbrot; bitmap_t *mbrot;
@ -184,9 +150,38 @@ int main() {
assert(mbrot->pixels != NULL); assert(mbrot->pixels != NULL);
/* Compute. */ /* Compute. */
#pragma omp parallel for #pragma omp parallel for schedule (dynamic, 50000)
for (unsigned int y = 0; y < mbrot->height; y++) { 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. */ /* Save PNG. */

Loading…
Cancel
Save