aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2024-04-19 22:29:11 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2024-04-19 22:29:11 -0400
commit625d99871e5d18e0aa54a95cfce2fa37e46b4095 (patch)
tree05cca9f88f963d9d1b3559890cb53b5700cb27cd /src
parent4b34ef523dc51cf6a0df4fe91150aa9c5e4ffc48 (diff)
implemented multibrot and mandelbrot serial pixel functions
Diffstat (limited to 'src')
-rw-r--r--src/mandelbrot.c52
1 files changed, 50 insertions, 2 deletions
diff --git a/src/mandelbrot.c b/src/mandelbrot.c
index 094ea0e..63db30d 100644
--- a/src/mandelbrot.c
+++ b/src/mandelbrot.c
@@ -1,3 +1,51 @@
-int main(const int argc, const char* argv[]){
- return 0;
+#include <complex.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#include "plotting.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 esacpe algorithm
+ */
+size_t mandelbrot(double complex z0, size_t max_iterations) {
+ double complex z = 0.0 + 0.0*I;
+ 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(double complex z0, size_t max_iterations, uintmax_t d){
+ double complex z = 0.0 + 0.0*I;
+ 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;
+}
+
+
+int main(const int argc, const char *argv[]) {
+ double complex z = 1.0 + 0.0*I;
+ size_t result = mandelbrot(z, 1000);
+ printf("Input: %f+%fI\n", creal(z), cimag(z));
+ printf("result: %zu\n", result);
}