LFTDIR := Libft/
LFT := $(LFTDIR)libft.a
-SRCS := main.c complex.c color.c event_handling.c
+SRCS := main.c complex.c color.c event_handling.c fractals.c
OBJS := $(SRCS:%.c=%.o)
all : $(NAME)
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:50:39 by ljiriste #+# #+# */
-/* Updated: 2023/11/11 18:50:41 by ljiriste ### ########.fr */
+/* Updated: 2024/01/19 10:56:22 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
return (res);
}
+t_complex complex_conj(t_complex z)
+{
+ z.i = -z.i;
+ return (z);
+}
+
double complex_norm(t_complex x)
{
return (sqrt(x.r * x.r + x.i * x.i));
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:51:27 by ljiriste #+# #+# */
-/* Updated: 2023/11/11 18:51:28 by ljiriste ### ########.fr */
+/* Updated: 2024/01/19 10:56:11 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
t_complex to_complex(double x, double y);
t_complex complex_add(t_complex x, t_complex y);
t_complex complex_mul(t_complex x, t_complex y);
+t_complex complex_conj(t_complex z);
double complex_norm(t_complex x);
#endif
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* fractals.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/12/05 19:57:50 by ljiriste #+# #+# */
+/* Updated: 2024/01/19 11:30:08 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "vect2.h"
+#include "complex.h"
+#include "fractol.h"
+#include <math.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.));
+}
+
+double mandelbrot(t_set_man *settings, double x, double y)
+{
+ int count;
+ t_complex c;
+ t_complex z;
+
+ c.r = x;
+ c.i = y;
+ count = 0;
+ z.r = 0;
+ z.i = 0;
+ if (complex_norm(c) > 4)
+ return (0);
+ while (complex_norm(z) < settings->threshold && count < settings->detail)
+ {
+ z = complex_add(complex_mul(z, z), c);
+ ++count;
+ }
+ if (count == settings->detail)
+ return (-1);
+ return (fmod((double)(count + 1 - log(log(complex_norm(z)) / log(2)) / log(2)) / settings->color_stability, 1.));
+}
+
+double tricorn(t_set_man *settings, double x, double y)
+{
+ int count;
+ t_complex c;
+ t_complex z;
+
+ c.r = x;
+ c.i = y;
+ count = 0;
+ z.r = 0;
+ z.i = 0;
+ if (complex_norm(c) > 4)
+ return (0);
+ while (complex_norm(z) < settings->threshold && count < settings->detail)
+ {
+ z = complex_add(complex_mul(complex_conj(z), complex_conj(z)), c);
+ ++count;
+ }
+ if (count == settings->detail)
+ return (-1);
+ return (fmod((double)(count + 1 - log(log(complex_norm(z)) / log(2)) / log(2)) / settings->color_stability, 1.));
+}
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* julia.h :+: :+: :+: */
+/* fractals.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 */
+/* Created: 2024/01/19 10:56:55 by ljiriste #+# #+# */
+/* Updated: 2024/01/19 11:01:53 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
-#include <math.h>
-#include "vect2.h"
-#include "complex.h"
+#ifndef FRACTALS_H
+# define FRACTALS_H
+
+# include "fractol.h"
double general_julia(void *zeroth, double resolution,
- void (*tested_f)(void *), int (*is_over_thresh)(void *))
-{
- int count;
+ void (*tested_f)(void *), int (*is_over_thresh)(void *));
+double mandelbrot(t_set_man *settings, double x, double y);
+double tricorn(t_set_man *settings, double x, double y);
- 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.));
-}
+#endif //FRACTALS_H
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/27 14:29:26 by ljiriste #+# #+# */
-/* Updated: 2024/01/18 17:14:33 by ljiriste ### ########.fr */
+/* Updated: 2024/01/19 11:21:04 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#include "complex.h"
#include "color.h"
#include "vect2.h"
+#include "fractals.h"
#include "fractol.h"
#include "libft.h"
#include <mlx.h>
return ;
}
-double mandelbrot(t_set_man *settings, double x, double y)
-{
- int count;
- t_complex c;
- t_complex z;
-
- c.r = x;
- c.i = y;
- count = 0;
- z.r = 0;
- z.i = 0;
- if (complex_norm(c) > 4)
- return (0);
- while (complex_norm(z) < settings->threshold && count < settings->detail)
- {
- z = complex_add(complex_mul(z, z), c);
- ++count;
- }
- if (count == settings->detail)
- return (-1);
- return (fmod((double)(count + 1 - log(log(complex_norm(z)) / log(2)) / log(2)) / settings->color_stability, 1.));
-}
-
t_color get_img_pixel_color(t_img *img, int x, int y)
{
char *px_addr;