Add general function for constructing Julia sets
authorLukas Jiriste <ljiriste@student.42prague.com>
Tue, 5 Dec 2023 19:20:21 +0000 (20:20 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Tue, 5 Dec 2023 19:20:21 +0000 (20:20 +0100)
This function has different prototype that mandelbrot function so some
work should be done about unifying it for easier swapping of the two.

This function may be used to construct specialized functions.

julia.c [new file with mode: 0644]

diff --git a/julia.c b/julia.c
new file mode 100644 (file)
index 0000000..aa63a9a
--- /dev/null
+++ b/julia.c
@@ -0,0 +1,31 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   julia.h                                            :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2023/12/05 19:57:50 by ljiriste          #+#    #+#             */
+/*   Updated: 2023/12/05 20:16:54 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include <math.h>
+#include "vect2.h"
+#include "complex.h"
+
+double general_julia(void *zeroth, double resolution,
+                                               void (*tested_f)(void *), int (*is_over_thresh)(void *))
+{
+       int             count;
+
+       count = 0;
+       while (!is_over_thresh(zeroth) && count < 100 * resolution)
+       {
+               tested_f(zeroth);
+               ++count;
+       }
+       if (count == 100 * resolution)
+               return (-1);
+       return (fmod(count / 100., 1.));
+}