--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* hooked.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2023/12/05 19:35:01 by ljiriste #+# #+# */
+/* Updated: 2023/12/05 19:46:30 by ljiriste ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <X11/X.h>
+#include <X11/keysym.h>
+#include <mlx.h>
+#include "fractol.h"
+#include "vect2.h"
+
+int handle_key_press(int keycode, t_session *s)
+{
+ if (keycode == XK_Escape)
+ close_win(s);
+ return (0);
+}
+
+int handle_mouse_press(int button, int x, int y, t_session *s)
+{
+ double delta_zoom;
+
+ if (button == Button4)
+ delta_zoom = 0.5;
+ else if (button == Button5)
+ delta_zoom = 2;
+ if (button == Button4 || button == Button5)
+ {
+ change_zoom(&s->view, (t_vect2){.x = x, .y = y}, delta_zoom);
+ draw_fractal(s);
+ }
+ return (0);
+}
+
+/* valgrind indicates an issue when the draw_fractal is in proccess
+ * while and ESC is pressed thus ending the program.
+ *
+ * Setting the condition to less than 1 basically turns this redrawing
+ * off.
+ */
+int no_event_handle(t_session *s)
+{
+ if (s->view.resolution < 1)
+ {
+ s->view.draw_whole = 0;
+ s->view.resolution *= 2;
+ draw_fractal(s);
+ }
+ return (0);
+}
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 18:51:29 by ljiriste #+# #+# */
-/* Updated: 2023/11/11 18:51:32 by ljiriste ### ########.fr */
+/* Updated: 2023/12/05 19:47:36 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
};
typedef struct s_session t_session;
+int handle_key_press(int keycode, t_session *s);
+int handle_mouse_press(int button, int x, int y, t_session *s);
+int no_event_handle(t_session *s);
+int draw_fractal(t_session *s);
+void change_zoom(t_view *view, t_vect2 invariant, double d_zoom);
+int close_win(t_session *s);
#endif
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/27 14:29:26 by ljiriste #+# #+# */
-/* Updated: 2023/11/11 18:50:45 by ljiriste ### ########.fr */
+/* Updated: 2023/12/05 19:51:07 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#include <X11/X.h>
#include <X11/keysym.h>
+#include <mlx.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
-#include <mlx.h>
#include "libft.h"
#include "fractol.h"
#include "complex.h"
double mandelbrot(double x, double y, double resolution)
{
- double threshold;
- const double min_threshold = 2.5;
- double max_count;
+ const double threshold = 1000;
+ const double log2 = log(2);
int count;
t_complex c;
t_complex z;
c.r = x;
c.i = y;
- max_count = 100 * resolution;
- threshold = 3;
- if (threshold < min_threshold)
- threshold = min_threshold;
count = 0;
z.r = 0;
z.i = 0;
- while (complex_norm(z) < threshold && count < max_count)
+ while (complex_norm(z) < threshold && count < 100 * resolution)
{
z = complex_add(complex_mul(z, z), c);
++count;
}
- if (count == max_count)
+ if (count == 100 * resolution)
return (-1);
- return (fmod(count / 100., 1.));
+ return (fmod((count + 1 - log(log(complex_norm(z)) / log2) / log2) / 100., 1.));
}
-
int draw_fractal(t_session *s)
{
int x;
view->pixel_size.y /= d_zoom;
view->window_coord.x += view->pixel_size.x * invariant.x * (d_zoom - 1);
view->window_coord.y -= view->pixel_size.y * invariant.y * (d_zoom - 1);
- view->resolution = 1;
+ //view->resolution = 1;
view->draw_whole = 1;
return ;
}
-int handle_key_press(int keycode, t_session *s)
-{
- if (keycode == XK_Escape)
- close_win(s);
- return (0);
-}
-
-int handle_mouse_press(int button, int x, int y, t_session *s)
-{
- double delta_zoom;
-
- if (button == Button4)
- delta_zoom = 0.5;
- else if (button == Button5)
- delta_zoom = 2;
- if (button == Button4 || button == Button5)
- {
- change_zoom(&s->view, (t_vect2){.x = x, .y = y}, delta_zoom);
- draw_fractal(s);
- }
- return (0);
-}
-
-/* valgrind indicates an issue when the draw_fractal is in proccess
- * while and ESC is pressed thus ending the program.
- *
- * Setting the condition to less than 1 basically turns this redrawing
- * off.
- */
-int no_event_handle(t_session *s)
-{
- if (s->view.resolution < 1)
- {
- s->view.draw_whole = 0;
- s->view.resolution *= 2;
- draw_fractal(s);
- }
- return (0);
-}
-
void init_view(t_session *s)
{
s->view.fractal = mandelbrot;
s->view.pixel_size.y = 0.01;
s->view.window_coord.x = -s->img.width / 2 * s->view.pixel_size.x;
s->view.window_coord.y = s->img.height / 2 * s->view.pixel_size.y;
- s->view.resolution = 1;
+ s->view.resolution = 10;
s->view.draw_whole = 1;
return ;
}
{
if (argc == 0)
free(argv);
- s->img.width = 200;
- s->img.height = 200;
+ s->img.width = 500;
+ s->img.height = 500;
init_view(s);
return ;
}