diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2024-04-24 00:30:57 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2024-04-24 00:30:57 -0400 |
| commit | 223c2a359a02602951771d960bd517d7cf6f3f9f (patch) | |
| tree | 75e3475fa12dbc15f52e902e4c8c3e8480008b37 /src/shared-fractals.c | |
| parent | 9e5fa12291500d52ccc554519e9692c5f003c63f (diff) | |
implemented the burning ship fractal
Diffstat (limited to 'src/shared-fractals.c')
| -rw-r--r-- | src/shared-fractals.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/shared-fractals.c b/src/shared-fractals.c index 3390e14..92c8c9a 100644 --- a/src/shared-fractals.c +++ b/src/shared-fractals.c @@ -1,6 +1,7 @@ #include "fractals.h" #include <omp.h> +#include <math.h> #include "fractals.h" #include "precision.h" @@ -60,6 +61,37 @@ void tricorn_grid(grid_t* grid, const size_t max_iterations){ data[i] = tricorn(grid_to_complex(grid, i), max_iterations); } } + +/* + * Computes the number of iterations it takes for a point z0 to become unbounded + * if the return value is equal to max_iterations, the point lies within the burningship set (oh no! I hope they have fire safety gear) + */ +size_t burning_ship(const CBASE complex z0, const size_t max_iterations) { + CBASE complex z = z0; + CBASE complex z_mod; + size_t iteration = 0; + + while (CABS(z) <= 2 && iteration < max_iterations) { + z_mod = RABS(CREAL(z)) + RABS(CIMAG(z))*I; + z = z_mod * z_mod + z0; + iteration++; + } + return iteration; +} + +/* + * Fills a grid with burning_ship values + */ +void burning_ship_grid(grid_t* grid, const size_t max_iterations){ + const size_t size = grid->size; + size_t* data = grid->data; + + #pragma omp parallel for default(none) shared(data, size, grid, max_iterations) schedule(dynamic) + for(size_t i = 0; i < size; i++){ + data[i] = burning_ship(grid_to_complex(grid, i), max_iterations); + } +} + /* * Computes the number of iterations it takes for a point z0 to diverge * if the return value is equal to max_iterations, the point lies within the multibrot set |
