/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/19 10:56:55 by ljiriste #+# #+# */
-/* Updated: 2024/04/25 09:43:50 by ljiriste ### ########.fr */
+/* Updated: 2024/04/25 15:10:14 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
# include "fractol.h"
-double general_julia(void *zeroth, double resolution,
- void (*tested_f)(void *), int (*is_over_thresh)(void *));
+//double general_julia(void *zeroth, double resolution,
+// void (*tested_f)(void *), int (*is_over_thresh)(void *));
+
double mandelbrot(t_set *settings, double x, double y);
double tricorn(t_set *settings, double x, double y);
+double julia(t_set *settings, double x, double y);
#endif //FRACTALS_H
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/05 19:57:50 by ljiriste #+# #+# */
-/* Updated: 2024/04/25 11:13:38 by ljiriste ### ########.fr */
+/* Updated: 2024/04/25 15:14:16 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
return (fmod((double)(count + 1 - log(log(norm) / log(2)) / log(2)) / color_stability, 1.));
}
+/*
double general_julia(void *zeroth, double resolution,
void (*tested_f)(void *), int (*is_over_thresh)(void *))
{
}
if (count == 100 * resolution)
return (-1);
- return (fmod(count / 100., 1.));
+ return (normalize_count(count, norm(zeroth), color_stability);
+}
+*/
+
+double julia(t_set *settings, double x, double y)
+{
+ int count;
+ t_complex c;
+ t_complex z;
+
+ c = settings->input.cpx;
+ z.r = x;
+ z.i = y;
+ count = 4;
+ if (complex_norm(c) > THRESHOLD)
+ return (normalize_count(count, THRESHOLD, settings->color_stability));
+ while (complex_norm(z) <= THRESHOLD && count < settings->detail)
+ {
+ z = complex_add(complex_mul(z, z), c);
+ ++count;
+ }
+ if (count == settings->detail)
+ return (-1);
+ return (normalize_count(count, complex_norm(z), settings->color_stability));
}
double mandelbrot(t_set *settings, double x, double y)
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/27 14:29:26 by ljiriste #+# #+# */
-/* Updated: 2024/04/25 14:46:40 by ljiriste ### ########.fr */
+/* Updated: 2024/04/25 15:45:14 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
s->view.palette = tri_color;
s->view.color_shift_speed = -0.001;
s->set.color_stability = 100;
+ s->set.input.cpx = (t_complex){.r = -0.4, .i = 0.6};
s->view.pixel_size.x = 0.01;
s->view.pixel_size.y = 0.01;
s->view.color_shift = 0;
return (mandelbrot);
else if (!ft_strcmp(name, "tri") || !ft_strcmp(name, "tricorn"))
return (tricorn);
+ else if (!ft_strcmp(name, "ju") || !ft_strcmp(name, "julia"))
+ return (julia);
else
return (NULL);
}
+// The input has to be a single string of the form i1,i2,... without whitespace
+// There has to be correct number of inputs for the chosen fractal
+// The input has to be composed of integers
+int is_correct_input(const char *str, t_fractal fractal)
+{
+ int count;
+
+ count = 0;
+ while (*str)
+ {
+ ++count;
+ while (ft_isdigit(*str) || *str == '-')
+ ++str;
+ if (*str == ',')
+ ++str;
+ else if (*str != '\0')
+ return (0);
+ }
+ if (fractal == julia && count != 2)
+ return (0);
+ return (1);
+}
+
+t_input parse_input(const char *str, t_fractal fractal)
+{
+ t_input res;
+
+ if (fractal == julia)
+ {
+ res.cpx.r = ft_atoi(str) / 1000.;
+ while (ft_isdigit(*str) || *str == '-')
+ ++str;
+ ++str;
+ res.cpx.i = ft_atoi(str) / 1000.;
+ }
+ return (res);
+}
+
int parse_arg(char **argv, t_session *s, int *i)
{
if (!ft_strcmp(argv[*i], "-w") && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i + 1]) > 0)
else if (!ft_strcmp(argv[*i], "-d") && ft_isint(argv[*i + 1]))
s->set.detail = ft_atoi(argv[++*i]);
else if (!ft_strcmp(argv[*i], "-f") && to_fractal(argv[*i + 1]) != NULL)
- s->view.fractal = to_fractal(argv[*i + 1]);
+ s->view.fractal = to_fractal(argv[++*i]);
else if (!ft_strcmp(argv[*i], "-s") && ft_isint(argv[*i + 1]))
s->view.color_shift_speed = ft_atoi(argv[++*i]) / 1000.;
else if (!ft_strcmp(argv[*i], "-c") && ft_isint(argv[*i + 1]))
s->set.color_stability = 10000 / ft_atoi(argv[++*i]);
+ else if (!ft_strcmp(argv[*i], "-i") && is_correct_input(argv[*i + 1], s->view.fractal))
+ s->set.input = parse_input(argv[++*i], s->view.fractal);
else
return (1);
return (0);
"\t-f\n\t\tOne of these fractals:\n"
"\t\t\tman[delbrot]\n"
"\t\t\ttri[corn]\n"
+ "\t\t\tju[lia]\n"
+ "\t-i\n\t\tInput for selected fractal. Has to be after -f option.\n"
+ "\t\t\tmandelbrot\t- no input\n"
+ "\t\t\ttricorn\t\t- no input\n"
+ "\t\t\tjulia\t\t- a complex number in the form real,complex\n"
+ "\t\t\t\t\t- the complex number will be divided by 1000 after input\n"
"\t-s\n\t\tSpeed of color change (negative values reverse the direction)\n"
"\t-c\n\t\tColorfulness\n"
"\nControls:\n"