Fix some Norm breaking formatting
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 26 Apr 2024 07:48:07 +0000 (09:48 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 26 Apr 2024 07:48:07 +0000 (09:48 +0200)
src/color.c
src/complex.c
src/event_handling.c
src/fractals.c
src/main.c
src/vect2.c [deleted file]

index 7445fd0596ba86275823de2eb33b735428633917..4f03a8c7103d14b6ce8b0177958f44b379f79c0e 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/11/11 18:50:32 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/04/26 09:23:27 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/04/26 09:39:44 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -15,7 +15,7 @@
 
 t_color        to_color(unsigned int num)
 {
-       t_color c;
+       t_color c;
 
        c.a = (num & 0xFF000000) >> 24;
        c.r = (num & 0x00FF0000) >> 16;
@@ -39,13 +39,6 @@ t_color      lin_interp_color(t_color zero, t_color one, double norm_par)
        return (res);
 }
 
-t_color        basic_palette(double normalized_par)
-{
-       if (normalized_par == 0.)
-               return (to_color(0x00000000));
-       return (lin_interp_color(to_color(0x000000FF), to_color(0x00FFFF00), normalized_par));
-}
-
 t_color        general_palette(double np, const t_color *array, size_t size)
 {
        size_t  i;
@@ -57,7 +50,7 @@ t_color       general_palette(double np, const t_color *array, size_t size)
        i = 1;
        while (i + 1 < size)
        {
-               if (np < (i + 1)/(double)size)
+               if (np < (i + 1) / (double)size)
                        return (lin_interp_color(array[i], array[i + 1], np * size - i));
                ++i;
        }
index ca2acfc7362e356d7bfc9e7d8f95627b5bb7518d..fbf3ca14b78751d13a265b95dfdbaf8f15603a09 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/11/11 18:50:39 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/01/19 10:56:22 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/04/26 09:34:05 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -46,7 +46,7 @@ t_complex     complex_conj(t_complex z)
        return (z);
 }
 
-double         complex_norm(t_complex x)
+double complex_norm(t_complex x)
 {
        return (sqrt(x.r * x.r + x.i * x.i));
 }
index 8452b796075e925b9df2e3d1a61b89f299fc83c6..86e279e7b0cd47ea2b747d80edea499c448b805e 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/12/05 19:35:01 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/04/25 14:13:46 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/04/26 09:38:15 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #define SHIFT_MULT 1.2
 #define SHIFT_THRESH 0.0001
 
+void   redraw(t_session *s)
+{
+       erase_calced(&s->img.calced);
+       s->img.undersample = s->img.undersample_max;
+       return ;
+}
+
 void   change_shift_speed(double *speed, double mult, double thresh)
 {
        if (-thresh < *speed && *speed < thresh)
@@ -47,7 +54,6 @@ void  change_shift_speed(double *speed, double mult, double thresh)
        return ;
 }
 
-
 static void    additional_keys(int keycode, t_session *s)
 {
        if (keycode == XK_KP_Multiply)
@@ -55,8 +61,7 @@ static void   additional_keys(int keycode, t_session *s)
                if (s->set.detail * DETAIL_MULT > s->set.detail)
                {
                        s->set.detail *= DETAIL_MULT;
-                       erase_calced(&s->img.calced);
-                       s->img.undersample = s->img.undersample_max;
+                       redraw(s);
                }
        }
        else if (keycode == XK_KP_Divide)
@@ -64,14 +69,15 @@ static void additional_keys(int keycode, t_session *s)
                if (s->set.detail >= DETAIL_MULT)
                {
                        s->set.detail /= DETAIL_MULT;
-                       erase_calced(&s->img.calced);
-                       s->img.undersample = s->img.undersample_max;
+                       redraw(s);
                }
        }
        else if (keycode == XK_KP_Up)
-               change_shift_speed(&s->view.color_shift_speed, SHIFT_MULT, SHIFT_THRESH);
+               change_shift_speed(&s->view.color_shift_speed,
+                       SHIFT_MULT, SHIFT_THRESH);
        else if (keycode == XK_KP_Down)
-               change_shift_speed(&s->view.color_shift_speed, -SHIFT_MULT, SHIFT_THRESH);
+               change_shift_speed(&s->view.color_shift_speed,
+                       -SHIFT_MULT, SHIFT_THRESH);
 }
 
 int    handle_key_press(int keycode, t_session *s)
@@ -87,14 +93,13 @@ int handle_key_press(int keycode, t_session *s)
        else if (keycode == XK_Right || keycode == XK_d)
                move_view(s, MOVE_AMOUNT, 0);
        else if (keycode == XK_KP_Add)
-               change_zoom(s, (t_vect2){.x = s->img.width / 2, .y = s->img.height / 2}, ZOOM_IN);
+               change_zoom(s, (t_vect2){.x = s->img.width / 2,
+                       .y = s->img.height / 2}, ZOOM_IN);
        else if (keycode == XK_KP_Subtract)
-               change_zoom(s, (t_vect2){.x = s->img.width / 2, .y = s->img.height / 2}, ZOOM_OUT);
+               change_zoom(s, (t_vect2){.x = s->img.width / 2,
+                       .y = s->img.height / 2}, ZOOM_OUT);
        else if (keycode == XK_r)
-       {
-               erase_calced(&s->img.calced);
-               s->img.undersample = s->img.undersample_max;
-       }
+               redraw(s);
        else
                additional_keys(keycode, s);
        if (keycode != XK_Escape)
@@ -129,7 +134,8 @@ int no_event_handle(t_session *s)
                        calculate_base(s);
                }
                draw_fractal(s);
-               s->view.color_shift = fmod(s->view.color_shift + s->view.color_shift_speed, 1.);
+               s->view.color_shift
+                       = fmod(s->view.color_shift + s->view.color_shift_speed, 1.);
                if (s->view.color_shift < 0)
                        s->view.color_shift += 1;
        }
index 605049592f97fe4c8ca2965f12e1025e0e8e13ca..00323625231dd995ada705d81c0cc311b6b9854c 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/12/05 19:57:50 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/04/25 15:14:16 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/04/26 09:45:56 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -19,7 +19,8 @@
 
 double normalize_count(int count, double norm, double color_stability)
 {
-       return (fmod((double)(count + 1 - log(log(norm) / log(2)) / log(2)) / color_stability, 1.));
+       return (fmod((double)(count + 1 - log(log(norm) / log(2)) / log(2))
+               / color_stability, 1.));
 }
 
 /*
@@ -97,7 +98,8 @@ double        tricorn(t_set *settings, double x, double y)
        z.r = 0;
        z.i = 0;
        if (complex_norm(c) > THRESHOLD)
-               return (normalize_count(count + 1, THRESHOLD, settings->color_stability));
+               return (normalize_count(count + 1,
+                               THRESHOLD, settings->color_stability));
        while (complex_norm(z) <= THRESHOLD && count < settings->detail)
        {
                z = complex_add(complex_mul(complex_conj(z), complex_conj(z)), c);
index 8825b3f354c02c435050b74026a1d49ab4febb7b..28e26c0aeb95bbfbfdadedda871477355258027d 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/10/27 14:29:26 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/04/26 08:52:24 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/04/26 09:41:56 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -86,8 +86,8 @@ void  calculate_base(t_session *s)
 
 void   draw_fractal(t_session *s)
 {
-       int     x;
-       int     y;
+       int             x;
+       int             y;
        double  param;
 
        x = 0;
@@ -153,16 +153,16 @@ void      move_img(t_img *img, int delta_x, int delta_y)
                        y = img->height - 1;
                while (0 <= y && y < img->height)
                {
-                       if (0 <= x - delta_x && x - delta_x < img->width &&
-                                       0 <= y - delta_y && y - delta_y < img->height)
+                       if (0 <= x - delta_x && x - delta_x < img->width
+                               && 0 <= y - delta_y && y - delta_y < img->height)
                        {
                                *(double *)ft_mat_access(&img->base, y - delta_y, x - delta_x)
                                        = *(double *)ft_mat_access(&img->base, y, x);
                                *(bool *)ft_mat_access(&img->calced, y - delta_y, x - delta_x) =
                                *(bool *)ft_mat_access(&img->calced, y, x);
                        }
-                       if (!(0 <= x + delta_x && x + delta_x < img->width &&
-                                       0 <= y + delta_y && y + delta_y < img->height))
+                       if (!(0 <= x + delta_x && x + delta_x < img->width
+                                       && 0 <= y + delta_y && y + delta_y < img->height))
                                *(bool *)ft_mat_access(&img->calced, y, x) = false;
                        y += 1 - 2 * (delta_y < 0);
                }
@@ -195,7 +195,8 @@ void        init_session(t_session *s)
        s->mlx = mlx_init();
        s->win = mlx_new_window(s->mlx, s->img.width, s->img.height, "Fract-ol");
        s->img.img = mlx_new_image(s->mlx, s->img.width, s->img.height);
-       s->img.addr = mlx_get_data_addr(s->img.img, &s->img.bpp, &s->img.bpl, &s->img.endian);
+       s->img.addr = mlx_get_data_addr(s->img.img,
+                       &s->img.bpp, &s->img.bpl, &s->img.endian);
        ft_mat_init(&s->img.calced, sizeof(bool));
        ft_mat_init(&s->img.base, sizeof(double));
        ft_mat_zeros(&s->img.calced, s->img.height, s->img.width);
@@ -279,25 +280,29 @@ t_input   parse_input(const char *str, t_fractal fractal)
 
 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)
-                       s->img.width = ft_atoi(argv[++*i]);
-               else if (!ft_strcmp(argv[*i], "-h") && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i + 1]) > 0)
-                       s->img.height = ft_atoi(argv[++*i]);
-               else if (!ft_strcmp(argv[*i], "-u") && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i]) >= 0 )
-                       s->img.undersample_max = ft_atoi(argv[++*i]);
-               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]);
-               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);
+       if (!ft_strcmp(argv[*i], "-w")
+               && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i + 1]) > 0)
+               s->img.width = ft_atoi(argv[++*i]);
+       else if (!ft_strcmp(argv[*i], "-h")
+               && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i + 1]) > 0)
+               s->img.height = ft_atoi(argv[++*i]);
+       else if (!ft_strcmp(argv[*i], "-u")
+               && ft_isint(argv[*i + 1]) && ft_atoi(argv[*i + 1]) >= 0)
+               s->img.undersample_max = ft_atoi(argv[++*i]);
+       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]);
+       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);
 }
 
 int    parse_args(int argc, char **argv, t_session *s)
@@ -320,37 +325,33 @@ int       parse_args(int argc, char **argv, t_session *s)
        return (0);
 }
 
-static const char      *help_str =
-       "This is the help for fractol by Lukáš Jiřiště\n"
-       "You can call the program as follows:\n\n"
-       "fractol -f <fractal name> [<option> <value>]\n"
-       "\nOptions:\n"
-       "\t-f\tOne of these fractals:\n"
-       "\t\t\tman[delbrot]\n"
-       "\t\t\ttri[corn]\n"
-       "\t\t\tju[lia]\n"
-       "\t-w\tWidth of window in pixels\n"
-       "\t-h\tHeight of window in pixels\n"
-       "\t-u\tMaximum undersample in pixels\n"
-       "\t-d\tDetail in maximum iterations\n"
-       "\t-i\tInput for selected fractal.\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\tSpeed of color change (negative values reverse the direction)\n"
-       "\t-c\tColorfulness\n"
-       "\nControls:\n"
-       "\tArrow keys and wasd can be used for movement.\n"
-       "\tOne can zoom in with + and zoom out with - keypad.\n"
-       "\tZoom can also be controlled with scrollwheel on the mouse.\n"
-       "\tThe detail is controlled by * (increase) and / (decrease) keys.\n"
-       "\tThe color change can be sped up and down with 8 and 2 keys.\n";
-
 void   print_help(void)
 {
-       ft_printf(help_str);
-       return ;
+       ft_printf("This is the help for fractol by Lukáš Jiřiště\n"
+               "You can call the program as follows:\n\n"
+               "fractol -f <fractal name> [<option> <value>]\n"
+               "\nOptions:\n"
+               "\t-f\tOne of these fractals:\n"
+               "\t\t\tman[delbrot]\n"
+               "\t\t\ttri[corn]\n"
+               "\t\t\tju[lia]\n"
+               "\t-w\tWidth of window in pixels\n"
+               "\t-h\tHeight of window in pixels\n"
+               "\t-u\tMaximum undersample in pixels\n"
+               "\t-d\tDetail in maximum iterations\n"
+               "\t-i\tInput for selected fractal.\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\tSpeed of color change (negative values reverse the direction)\n"
+               "\t-c\tColorfulness\n"
+               "\nControls:\n"
+               "\tArrow keys and wasd can be used for movement.\n"
+               "\tOne can zoom in with + and zoom out with - keypad.\n"
+               "\tZoom can also be controlled with scrollwheel on the mouse.\n"
+               "\tThe detail is controlled by * (increase) and / (decrease) keys.\n"
+               "\tThe color change can be sped up and down with 8 and 2 keys.\n");
 }
 
 void   cleanup(t_session *s)
diff --git a/src/vect2.c b/src/vect2.c
deleted file mode 100644 (file)
index 9c89526..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/* ************************************************************************** */
-/*                                                                            */
-/*                                                        :::      ::::::::   */
-/*   vect2.c                                            :+:      :+:    :+:   */
-/*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
-/*                                                +#+#+#+#+#+   +#+           */
-/*   Created: 2023/11/11 18:50:53 by ljiriste          #+#    #+#             */
-/*   Updated: 2023/11/11 18:50:59 by ljiriste         ###   ########.fr       */
-/*                                                                            */
-/* ************************************************************************** */
-
-#include "vect2.h"
-
-