aboutsummaryrefslogtreecommitdiff
path: root/src/event.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-02-24 15:39:22 +0100
committerCharles <sircharlesaze@gmail.com>2020-02-24 15:39:22 +0100
commitc6f87a62b31325e91bc8c847de9b20647a9b1cd8 (patch)
treeaacf869e3c22f8937637c3e7aa15794b2b4680f0 /src/event.c
parentc924493670af7285683295d7ab38991e018b65cf (diff)
downloadfractol-c6f87a62b31325e91bc8c847de9b20647a9b1cd8.tar.gz
fractol-c6f87a62b31325e91bc8c847de9b20647a9b1cd8.tar.bz2
fractol-c6f87a62b31325e91bc8c847de9b20647a9b1cd8.zip
Added julia fractal and mouse modify julia constant
Diffstat (limited to 'src/event.c')
-rw-r--r--src/event.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/event.c b/src/event.c
index 3f878f8..30b5c34 100644
--- a/src/event.c
+++ b/src/event.c
@@ -6,14 +6,14 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/24 09:52:35 by cacharle #+# #+# */
-/* Updated: 2020/02/24 14:08:20 by cacharle ### ########.fr */
+/* Updated: 2020/02/24 15:38:06 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
-#define MOVE_SPEED 0.2
-#define ZOOM_SPEED 1.1
+#define MOVE_SPEED 0.1
+#define ZOOM_SPEED 1.2
int event_quit(t_state *state)
{
@@ -23,7 +23,7 @@ int event_quit(t_state *state)
int event_keydown(int key, t_state *state)
{
- printf("%d\n", key);
+ /* printf("%d\n", key); */
if (key == MLXK_ESC)
state->running = false;
else if (key == MLXK_UP)
@@ -36,7 +36,7 @@ int event_keydown(int key, t_state *state)
state->center.r += state->plane.r * MOVE_SPEED;
else
return (0);
- render_update_window_complex(state);
+ state->updated = false;
return (0);
}
@@ -45,21 +45,41 @@ int event_mouse(int button, int x, int y, t_state *state)
(void)x;
(void)y;
- /* printf("%d\n", button); */
- /* printf("%d\n", x); */
- /* printf("%d\n", y); */
if (button == MLX_MOUSE_SCROLL_UP)
{
state->plane.r /= ZOOM_SPEED;
state->plane.i /= ZOOM_SPEED;
+ /* state->center.r += MOVE_SPEED * (double)(x - WINDOW_WIDTH / 2) / WINDOW_WIDTH; */
+ /* state->center.i += MOVE_SPEED * (double)(y - WINDOW_HEIGHT / 2) / WINDOW_HEIGHT; */
+
}
else if (button == MLX_MOUSE_SCROLL_DOWN)
{
state->plane.r *= ZOOM_SPEED;
state->plane.i *= ZOOM_SPEED;
+ /* state->center.r -= MOVE_SPEED * (double)(x - WINDOW_WIDTH / 2) / WINDOW_WIDTH; */
+ /* state->center.i -= MOVE_SPEED * (double)(y - WINDOW_HEIGHT / 2) / WINDOW_HEIGHT; */
}
else
return (0);
- render_update_window_complex(state);
+ state->updated = false;
+ return (0);
+}
+
+int event_mouse_motion(int x, int y, t_state *state)
+{
+ if (state->julia_const.r == NAN)
+ return (0);
+ if (x < 0)
+ x = 0;
+ if (x > WINDOW_WIDTH - 1)
+ x = WINDOW_WIDTH - 1;
+ if (y < 0)
+ y = 0;
+ if (y > WINDOW_HEIGHT - 1)
+ y = WINDOW_HEIGHT - 1;
+ state->julia_const.r = ((double)x / (double)WINDOW_WIDTH) * 4.0 - 2.0;
+ state->julia_const.i = ((double)y / (double)WINDOW_HEIGHT) * 4.0 - 2.0;
+ state->updated = false;
return (0);
}