aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2024-04-20 02:43:17 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2024-04-20 02:43:17 -0400
commit5cba5bc63de403c779fd4fa762216280d4396444 (patch)
treef1c2da748ab8f5bd88b40d09cd617838257dfb23
parent74c1057a1cea4ec5fc3a8f338b24af553cc83399 (diff)
reorganized src files
-rw-r--r--makefile4
-rw-r--r--src/fractals.c (renamed from src/mandelbrot.c)54
-rw-r--r--src/fractals.h9
-rw-r--r--src/grids.h4
-rw-r--r--src/plotting.h4
-rw-r--r--src/serial-fractals.c55
6 files changed, 71 insertions, 59 deletions
diff --git a/makefile b/makefile
index 83ba870..47967f4 100644
--- a/makefile
+++ b/makefile
@@ -7,7 +7,7 @@ SRC_DIR := src
BUILD_DIR := build
OBJ_DIR := $(BUILD_DIR)/objects
-TARGET := serial-fractal
+TARGET := fractals
SRCS := $(wildcard $(SRC_DIR)/*.c)
OBJS := $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS))
@@ -20,7 +20,7 @@ all: $(BUILD_DIR)/$(TARGET)
# Programs #
##############
-build/mandelbrot: $(OBJ_DIR)/serial-fractal.o $(OBJ_DIR)/grids.o
+build/fractals: $(OBJ_DIR)/fractals.o $(OBJ_DIR)/serial-fractals.o $(OBJ_DIR)/grids.o
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
diff --git a/src/mandelbrot.c b/src/fractals.c
index ee2585f..1e27b9c 100644
--- a/src/mandelbrot.c
+++ b/src/fractals.c
@@ -6,60 +6,8 @@
#include <stdlib.h>
#include "grids.h"
+#include "fractals.h"
-/*
- * 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 mandelbrot set
- * This is an implementation the escape algorithm
- */
-size_t mandelbrot(const double complex z0, const size_t max_iterations) {
- double complex z = z0;
- size_t iteration = 0;
-
- while (cabs(z) <= 2 && iteration < max_iterations) {
- z = z * z + z0;
- iteration++;
- }
- return iteration;
-}
-
-/*
- * 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
- * This is implementation closely matches mandelbrot
- * Note, only positive integer powers are supported
- */
-size_t multibrot(const double complex z0, const size_t max_iterations, const uintmax_t d){
- double complex z = z0;
- double complex ztemp;
- size_t iteration = 0;
- while(cabs(z) <= 2 && iteration < max_iterations){
- ztemp = z;
- for(size_t i = 0; i < d; i ++){
- ztemp *= ztemp;
- }
- z = ztemp + z0;
- iteration++;
- }
- return iteration;
-}
-
-/*
- * Computes ????? for a julia set
- * implementation of https://en.wikipedia.org/wiki/Julia_set#Pseudocode
- */
-size_t julia(const double R, const double complex z0, const double complex c, const size_t max_iterations){
- //FIXME: I'm notsure if this is currently implemented correctly
- if(R*R - R >= cabs(z0)) return 0;
- double complex z = z0;
-
- size_t iteration = 0;
- while(cabs(z) < R && iteration < max_iterations){
- z = z * z + c;
- iteration++;
- }
- return iteration;
-}
/*
* Converts a grid point into an complex number
diff --git a/src/fractals.h b/src/fractals.h
new file mode 100644
index 0000000..60d9013
--- /dev/null
+++ b/src/fractals.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include <complex.h>
+#include <stddef.h>
+#include <stdint.h>
+
+size_t mandelbrot(const double complex z0, const size_t max_iterations);
+size_t multibrot(const double complex z0, const size_t max_iterations, const uintmax_t d);
+size_t julia(const double R, const double complex z0, const double complex c, const size_t max_iterations);
diff --git a/src/grids.h b/src/grids.h
index 8de6375..f1581b3 100644
--- a/src/grids.h
+++ b/src/grids.h
@@ -1,8 +1,8 @@
+#pragma once
+
#include <stddef.h>
#include <stdbool.h>
-#pragma once
-
typedef struct {
size_t x;
size_t y;
diff --git a/src/plotting.h b/src/plotting.h
index d94c7bc..19d669b 100644
--- a/src/plotting.h
+++ b/src/plotting.h
@@ -1,7 +1,7 @@
-#include <stddef.h>
-
#pragma once
+#include <stddef.h>
+
typedef struct {
char red;
char green;
diff --git a/src/serial-fractals.c b/src/serial-fractals.c
new file mode 100644
index 0000000..c5b9c4e
--- /dev/null
+++ b/src/serial-fractals.c
@@ -0,0 +1,55 @@
+#include "fractals.h"
+/*
+ * 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 mandelbrot set
+ * This is an implementation the escape algorithm
+ */
+size_t mandelbrot(const double complex z0, const size_t max_iterations) {
+ double complex z = z0;
+ size_t iteration = 0;
+
+ while (cabs(z) <= 2 && iteration < max_iterations) {
+ z = z * z + z0;
+ iteration++;
+ }
+ return iteration;
+}
+
+/*
+ * 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
+ * This is implementation closely matches mandelbrot
+ * Note, only positive integer powers are supported
+ */
+size_t multibrot(const double complex z0, const size_t max_iterations, const uintmax_t d){
+ double complex z = z0;
+ double complex ztemp;
+ size_t iteration = 0;
+ while(cabs(z) <= 2 && iteration < max_iterations){
+ ztemp = z;
+ for(size_t i = 0; i < d; i ++){
+ ztemp *= ztemp;
+ }
+ z = ztemp + z0;
+ iteration++;
+ }
+ return iteration;
+}
+
+/*
+ * Computes ????? for a julia set
+ * implementation of https://en.wikipedia.org/wiki/Julia_set#Pseudocode
+ */
+size_t julia(const double R, const double complex z0, const double complex c, const size_t max_iterations){
+ //FIXME: I'm notsure if this is currently implemented correctly
+ if(R*R - R >= cabs(z0)) return 0;
+ double complex z = z0;
+
+ size_t iteration = 0;
+ while(cabs(z) < R && iteration < max_iterations){
+ z = z * z + c;
+ iteration++;
+ }
+ return iteration;
+}
+