diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2024-04-19 22:29:31 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2024-04-19 22:29:31 -0400 |
| commit | c1eb35ea06ba95a18d9ab4ff53ed3b67be35af8b (patch) | |
| tree | 2587470e6fda5f1f815d3b7ab67e71737ddafca8 /src/plotting.c | |
| parent | 625d99871e5d18e0aa54a95cfce2fa37e46b4095 (diff) | |
intial work on plotting functions
Diffstat (limited to 'src/plotting.c')
| -rw-r--r-- | src/plotting.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/plotting.c b/src/plotting.c new file mode 100644 index 0000000..96d76c5 --- /dev/null +++ b/src/plotting.c @@ -0,0 +1,93 @@ +#include <stdlib.h> +#include <string.h> +#include "plotting.h" + +/* + * Gets the corresponding color for a given number of iterations according to a gradient + */ +color get_color(size_t iterations, size_t max_iterations, gradient map){ + size_t val = (max_iterations - iterations) / max_iterations; + color color; + + //TODO: map the interval of [0,max_iterations] to a value given a gradient + return color; +} + +/* + * Gets the associated "red" value for a given number of iterations according to a gradient + */ +char get_red(size_t iterations, size_t max_iterations, gradient map){ + char red; + + return red; +} + +/* + * Gets the associated "green" value for a given number of iterations according to a gradient + */ +char get_green(size_t iterations, size_t max_iterations, gradient map){ + char green; + + return green; +} + +/* + * Gets the associated "blue" value for a given number of iterations according to a gradient + */ +char get_blue(size_t iterations, size_t max_iterations, gradient map){ + char blue; + + return blue; +} + +colors_t* create_colors(size_t x, size_t y){ + if(x <= 0 || y <= 0) return NULL; + + char* red = malloc(x*y); + char* green = malloc(x*y); + char* blue = malloc(x*y); + + if(!red || !green || !blue){ + free(red); free(green); free(blue); + return NULL; + } + + colors_t* colors = malloc(sizeof(colors_t)); + if(!colors){ + free(red); free(green); free(blue); + return NULL; + } + + colors->x = x; + colors->y = y; + colors->size = x*y; + colors->red = red; + colors->green = green; + colors->blue = blue; + + return colors; +} + +colors_t* copy_colors(colors_t* colors){ + if(!colors) return NULL; + + colors_t* colors_copy = create_colors(colors->x, colors->y); + if(!colors_copy) return NULL; + + const size_t size = colors->size; + + memcpy(colors_copy->red, colors->red, size); + memcpy(colors_copy->green, colors->green, size); + memcpy(colors_copy->blue, colors->blue, size); + + return colors_copy; +} + +void free_colors(colors_t* colors){ + if(!colors) return; + + free(colors->red); + free(colors->green); + free(colors->blue); + free(colors); +} |
