aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--makefile18
-rw-r--r--src/plotting.c93
-rw-r--r--src/plotting.h31
3 files changed, 140 insertions, 2 deletions
diff --git a/makefile b/makefile
index 14478ef..1cbae10 100644
--- a/makefile
+++ b/makefile
@@ -1,13 +1,27 @@
-CC :=
+CC := gcc-13
CPPFLAGS :=
+CFLAGS := -Wall
LDFLAGS :=
-all:
+all:
##############
# Programs #
##############
+SRCS := mandelbrot.c plotting.c
+OBJS := $(SRC:.c=.o)
+OBJS_DIR := build/objs
+
+build/mandelbrot: $(addprefix $(OBJS_DIR)/, $(OBJS))
+ $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
+
+$(OBJS_DIR)/%.o: src/%.c $(OBJS_DIR)
+ $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
+
+$(OBJS_DIR):
+ mkdir -p $@
+
################
# Animations #
################
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);
+}
diff --git a/src/plotting.h b/src/plotting.h
new file mode 100644
index 0000000..9d72b69
--- /dev/null
+++ b/src/plotting.h
@@ -0,0 +1,31 @@
+#include <stddef.h>
+
+#pragma once
+
+typedef struct {
+ char red;
+ char green;
+ char blue;
+} color;
+
+typedef struct {
+ size_t x;
+ size_t y;
+ size_t size;
+ char* red;
+ char* green;
+ char* blue;
+} colors_t;
+
+typedef char gradient;
+
+// for AoS
+color get_color(size_t iterations, size_t max_iterations, gradient map);
+
+// for SoA
+char get_red(size_t iterations, size_t max_iterations, gradient map);
+char get_green(size_t iterations, size_t max_iterations, gradient map);
+char get_blue(size_t iterations, size_t max_iterations, gradient map);
+colors_t* create_colors(size_t x, size_t y);
+colors_t* copy_colors(colors_t* colors);
+void free_colors(colors_t* colors);