diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2024-04-24 00:10:48 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2024-04-24 00:10:48 -0400 |
| commit | 9e5fa12291500d52ccc554519e9692c5f003c63f (patch) | |
| tree | 96a80b5fbe2cdb4f497c8a0d3e1294a2d0102764 /src/serial-fractals.c | |
| parent | 9ba9c47a952ce6966b333af579bd39c636080fbc (diff) | |
improved cli, implemented tricorn and multicorn
Diffstat (limited to 'src/serial-fractals.c')
| -rw-r--r-- | src/serial-fractals.c | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/src/serial-fractals.c b/src/serial-fractals.c index 5831f92..2647d11 100644 --- a/src/serial-fractals.c +++ b/src/serial-fractals.c @@ -3,7 +3,7 @@ #include "grids.h" /* - * Computes the number of iterations it takes for a point z0 to diverge + * 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 mandelbrot set * This is an implementation the escape algorithm */ @@ -31,7 +31,34 @@ void mandelbrot_grid(grid_t* grid, const size_t max_iterations){ } /* - * Computes the number of iterations it takes for a point z0 to diverge + * 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 tricorn set + * This is nearly identical to mandelbrot, except for the complex conjugate + */ +size_t tricorn(const CBASE complex z0, const size_t max_iterations){ + CBASE complex z = z0; + size_t iteration = 0; + while(CABS(z) <= 2 && iteration < max_iterations){ + z = CONJ(z * z) + z0; + iteration++; + } + return iteration; +} + +/* + * Fills a grid with tricorn values + */ +void tricorn_grid(grid_t* grid, const size_t max_iterations){ + const size_t size = grid->size; + size_t* data = grid->data; + + for(size_t i = 0; i < size; i++){ + 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 multibrot set * This is implementation closely matches mandelbrot, but uses cpow which might degrade performance. */ @@ -39,7 +66,7 @@ size_t multibrot(const CBASE complex z0, const size_t max_iterations, const doub CBASE complex z = z0; size_t iteration = 0; while(CABS(z) <= 2 && iteration < max_iterations){ - z = cpow(z, d) + z0; + z = CPOW(z, d) + z0; iteration++; } return iteration; @@ -58,6 +85,32 @@ void multibrot_grid(grid_t* grid, const size_t max_iterations, const double d){ } /* + * Computes the number ofiterations it takes for a point z0 to become unbounded + * if the return value is equal to max_iterations, the point lies within the multicorn set + * This function is to tricorn as multibrot is to mandelbrot + */ +size_t multicorn(const CBASE complex z0, const size_t max_iterations, const double d){ + CBASE complex z = z0; + size_t iteration = 0; + while(CABS(z) <= 2 && iteration < max_iterations){ + z = CONJ(CPOW(z, d)) + z0; + iteration++; + } + return iteration; +} + +/* + * Fills a grid with multicorn values + */ +void multicorn_grid(grid_t* grid, const size_t max_iterations, const double d){ + const size_t size = grid->size; + size_t* data = grid->data; + for(size_t i = 0; i < size; i ++){ + data[i] = multicorn(grid_to_complex(grid, i), max_iterations, d); + } +} + +/* * Computes ????? for a julia set * implementation of https://en.wikipedia.org/wiki/Julia_set#Pseudocode * |
