Compare commits

...

10 commits

Author SHA1 Message Date
Gregory Tertyshny
02fe8897ee fix makefile 2017-03-25 18:02:30 +02:00
Gregory Tertyshny
811e2c57df some changes in mouse control and in header file 2017-03-25 17:37:20 +02:00
Gregory Tertyshny
cea72dc4b8 fix bug in mouse moution 2017-03-25 15:02:48 +02:00
Gregory Tertyshny
ec0d447081 new features ported from macos branch 2017-03-25 14:59:42 +02:00
Gregory Tertyshny
4a955f0f17 fix mouse hook 2017-03-24 21:13:50 +02:00
Gregory Tertyshny
47a774f975 fix gnl in libft 2017-03-24 20:42:07 +02:00
Gregory Tertyshny
8040c2433a author file 2017-03-24 20:09:13 +02:00
Gregory Tertyshny
961ea09e1d libft check 2017-03-24 20:07:40 +02:00
Gregory Tertyshny
bd7baf18bd header norm check 2017-03-24 19:59:25 +02:00
Gregory Tertyshny
91cd64dba8 rm CmakeLists 2017-03-24 19:48:57 +02:00
11 changed files with 215 additions and 135 deletions

View file

@ -1,29 +0,0 @@
cmake_minimum_required(VERSION 3.6)
project(fractol)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wextra")
include_directories(inc libft/includes minilibx) # headers
link_directories(libft minilibx) # libraries
set(SOURCE_FILES
src/main.c
src/help_func.c
src/color.c
src/fractol_init.c
src/hooks.c
src/image_routine.c
src/complex.c
src/julia.c
src/threads_routine.c
src/mandelbrot.c
src/burning_ship.c
src/fractal_routine.c
src/hooks_funcs.c
src/parse_input.c
src/hooks_funcs_1.c
src/hooks_funcs_2.c) # sources
add_executable(fractol ${SOURCE_FILES}) # compilation
target_link_libraries(fractol -lft -lmlx "-framework OpenGL" "-framework AppKit") # linkage

View file

@ -6,7 +6,7 @@
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ # # By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2016/12/14 16:54:48 by gtertysh #+# #+# # # Created: 2016/12/14 16:54:48 by gtertysh #+# #+# #
# Updated: 2017/03/24 13:59:39 by gtertysh ### ########.fr # # Updated: 2017/03/25 17:59:43 by gtertysh ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -102,7 +102,7 @@ libclean:
@make clean -s -C $(LIBFT_DIR) @make clean -s -C $(LIBFT_DIR)
@make clean -s -C $(MLX_DIR) @make clean -s -C $(MLX_DIR)
libfclean: libfclean: libclean
@make fclean -s -C $(LIBFT_DIR) @make fclean -s -C $(LIBFT_DIR)
re: fclean libfclean all re: fclean libfclean all

1
author Normal file
View file

@ -0,0 +1 @@
gtertysh

View file

@ -6,7 +6,7 @@
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */ /* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/16 20:59:04 by gtertysh #+# #+# */ /* Created: 2017/03/16 20:59:04 by gtertysh #+# #+# */
/* Updated: 2017/03/24 14:00:01 by gtertysh ### ########.fr */ /* Updated: 2017/03/25 17:36:38 by gtertysh ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,10 +16,8 @@
# include "libft.h" # include "libft.h"
# include "mlx.h" # include "mlx.h"
# include <math.h> # include <math.h>
# include <fcntl.h>
# include <pthread.h> # include <pthread.h>
# include <time.h> # include <time.h>
# include <unistd.h>
# define HEIGHT 700 # define HEIGHT 700
# define WIDTH 1300 # define WIDTH 1300
@ -40,7 +38,6 @@
# define NUM_THREADS 24 # define NUM_THREADS 24
typedef struct s_complex typedef struct s_complex
{ {
long double rl; long double rl;
@ -86,14 +83,14 @@ typedef struct s_image
int bpp; int bpp;
} t_image; } t_image;
typedef t_color (*frac_func)(t_frac_data *data, int x, int y); typedef t_color (*t_frac_func)(t_frac_data *data, int x, int y);
typedef struct s_fractol typedef struct s_fractol
{ {
void *mlx; void *mlx;
void *win; void *win;
t_frac_data *frac; t_frac_data *frac;
frac_func fr_funcs[3]; t_frac_func fr_funcs[3];
int w_height; int w_height;
int w_width; int w_width;
t_image *img; t_image *img;
@ -104,7 +101,7 @@ typedef struct s_thread_data
t_fractol fr; t_fractol fr;
int y_start; int y_start;
int y_end; int y_end;
frac_func fractal_func; t_frac_func fractal_func;
} t_thread_data; } t_thread_data;
void quit(t_fractol *fractol); void quit(t_fractol *fractol);
@ -118,7 +115,7 @@ t_gradient random_gradient(void);
t_fractol *fractol_init(void *mlx, int frac_type); t_fractol *fractol_init(void *mlx, int frac_type);
int key_hook(int keycode, void *m); int key_hook(int keycode, void *m);
int mouse_move_hook( int x, int y, void *fr); int mouse_move_hook(int x, int y, void *fr);
int mouse_button_hook(int btn, int x, int y, void *fr); int mouse_button_hook(int btn, int x, int y, void *fr);
void put_pixel_to_image(int x, int y, t_color col, t_fractol *fr); void put_pixel_to_image(int x, int y, t_color col, t_fractol *fr);
@ -137,6 +134,8 @@ void parallel_fractal(t_fractol *fr);
void zoom_in(t_fractol *frm, int x, int y); void zoom_in(t_fractol *frm, int x, int y);
void zoom_out(t_fractol *fr); void zoom_out(t_fractol *fr);
void zoom_in_key(t_fractol *fr);
void zoom_out_key(t_fractol *fr);
void move_left(t_fractol *fr); void move_left(t_fractol *fr);
void move_right(t_fractol *fr); void move_right(t_fractol *fr);
void move_up(t_fractol *fr); void move_up(t_fractol *fr);
@ -148,4 +147,7 @@ int change_real(t_fractol *fr, int x, int *start_x);
int change_imagianry(t_fractol *fr, int x, int *start_x); int change_imagianry(t_fractol *fr, int x, int *start_x);
void gradient_hook(t_fractol *fr); void gradient_hook(t_fractol *fr);
void julia_samples(t_fractol *fr, double real, double img);
void mandelbrot_samples(t_fractol *fr, double x, double y);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */ /* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/04 19:13:25 by gtertysh #+# #+# */ /* Created: 2016/12/04 19:13:25 by gtertysh #+# #+# */
/* Updated: 2016/12/06 19:47:50 by gtertysh ### ########.fr */ /* Updated: 2017/03/24 20:06:06 by gtertysh ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -5,14 +5,14 @@
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */ /* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/04 15:59:21 by gtertysh #+# #+# */ /* Created: 2017/01/28 18:15:15 by gtertysh #+# #+# */
/* Updated: 2016/12/06 19:45:44 by gtertysh ### ########.fr */ /* Updated: 2017/03/24 20:41:17 by gtertysh ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #include "libft.h"
static t_fd *new_node(int fd) t_fd *new_node(int fd)
{ {
t_fd *new; t_fd *new;
@ -27,7 +27,7 @@ static t_fd *new_node(int fd)
return (new); return (new);
} }
static t_fd *find_fd(int fd, t_fd **cur_fd) t_fd *find_fd(int fd, t_fd **cur_fd)
{ {
if (!*cur_fd) if (!*cur_fd)
return ((*cur_fd = new_node(fd))); return ((*cur_fd = new_node(fd)));
@ -40,6 +40,59 @@ static t_fd *find_fd(int fd, t_fd **cur_fd)
return ((*cur_fd = new_node(fd))); return ((*cur_fd = new_node(fd)));
} }
int check_reminder(t_fd *c, char **line)
{
char *substr;
char *old_line;
old_line = *line;
if (c->n)
{
if ((c->t = ft_strchr(c->n, '\n')))
{
substr = ft_strsub(c->n, 0, c->t - c->n);
*line = ft_strjoin(*line, substr);
free(substr);
c->n = ++(c->t);
return (1);
}
else
{
*line = ft_strjoin(*line, c->n);
c->n = 0;
}
free(old_line);
}
return (0);
}
int check_buf(t_fd *c, char **line)
{
char *substr;
char *old_line;
old_line = *line;
while ((c->readed = read(c->fd, c->b, BUFF_SIZE)))
{
if (c->readed == -1)
return (-1);
c->b[c->readed] = 0;
if ((c->n = ft_strchr(c->b, '\n')))
{
substr = ft_strsub(c->b, 0, c->n++ - c->b);
old_line = *line;
*line = ft_strjoin(*line, substr);
free(substr);
free(old_line);
break ;
}
old_line = *line;
*line = ft_strjoin(*line, c->b);
free(old_line);
}
return (1);
}
int get_next_line(const int fd, char **line) int get_next_line(const int fd, char **line)
{ {
static t_fd *head_fd; static t_fd *head_fd;
@ -50,27 +103,11 @@ int get_next_line(const int fd, char **line)
*line = ft_strnew(0); *line = ft_strnew(0);
c = find_fd(fd, &head_fd); c = find_fd(fd, &head_fd);
c->readed = 0; c->readed = 0;
if (c->n) { if (check_reminder(c, line))
if ((c->t = strchr(c->n, '\n')) &&
(*line = ft_strjoin(*line, ft_strsub(c->n, 0, (c->t - c->n)))) &&
(c->n = ++(c->t)))
{
return (1); return (1);
} if (check_buf(c, line) == -1)
else if ((*line = ft_strjoin(*line, c->n))) return (-1);
{ if ((c->readed == 0) && !ft_strlen(*line))
c->n = 0;
}
}
while ((c->readed = read(c->fd, c->b, BUFF_SIZE)))
{
c->b[c->readed] = 0;
if ((c->n = strchr(c->b, '\n')) &&
(*line = ft_strjoin(*line, ft_strsub(c->b, 0, (c->n++ - c->b)))))
break;
*line = ft_strjoin(*line, c->b);
}
if (!c->readed && !ft_strlen(*line))
return (0); return (0);
return (1); return (1);
} }

View file

@ -6,7 +6,7 @@
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */ /* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 12:21:43 by gtertysh #+# #+# */ /* Created: 2016/11/28 12:21:43 by gtertysh #+# #+# */
/* Updated: 2016/12/27 18:02:00 by gtertysh ### ########.fr */ /* Updated: 2017/03/24 20:05:11 by gtertysh ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */ /* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 19:37:32 by gtertysh #+# #+# */ /* Created: 2017/03/24 19:37:32 by gtertysh #+# #+# */
/* Updated: 2017/03/24 19:37:33 by gtertysh ### ########.fr */ /* Updated: 2017/03/25 17:35:04 by gtertysh ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -46,7 +46,7 @@ t_frac_data *frac_init(int frac_type)
else else
complex_equal(0, 0, &f->com_const); complex_equal(0, 0, &f->com_const);
f->com_rl_im_change = 1; f->com_rl_im_change = 1;
f->allow_mouse_change = -1; f->allow_mouse_change = 1;
f->mov.x = 0; f->mov.x = 0;
f->mov.y = 0; f->mov.y = 0;
f->mov.z = 1; f->mov.z = 1;

31
src/fractal_samples.c Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractal_samples.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 14:52:57 by gtertysh #+# #+# */
/* Updated: 2017/03/25 14:52:58 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void julia_samples(t_fractol *fr, double real, double img)
{
complex_equal(real, img, &fr->frac->com_const);
new_and_clear_image(fr);
parallel_fractal(fr);
mlx_put_image_to_window(fr->mlx, fr->win, fr->img->ptr, 0, 0);
}
void mandelbrot_samples(t_fractol *fr, double x, double y)
{
fr->frac->mov.x = x;
fr->frac->mov.y = y;
fr->frac->mov.z = 1;
new_and_clear_image(fr);
parallel_fractal(fr);
mlx_put_image_to_window(fr->mlx, fr->win, fr->img->ptr, 0, 0);
}

View file

@ -6,30 +6,52 @@
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */ /* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/16 18:59:03 by gtertysh #+# #+# */ /* Created: 2017/03/16 18:59:03 by gtertysh #+# #+# */
/* Updated: 2017/03/24 14:02:46 by gtertysh ### ########.fr */ /* Updated: 2017/03/25 14:59:09 by gtertysh ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "fractol.h" #include "fractol.h"
void sample(t_fractol *fr, int key)
{
if (fr->frac->frac_type == 0 && key == 18)
julia_samples(fr, -1.037, 0.17);
if (fr->frac->frac_type == 0 && key == 19)
julia_samples(fr, -0.1, 0.651);
if (fr->frac->frac_type == 0 && key == 20)
julia_samples(fr, 0.285, 0.01);
if (fr->frac->frac_type == 1 && key == 18)
mandelbrot_samples(fr, -1.30000000000002603931, 0);
if (fr->frac->frac_type == 1 && key == 19)
mandelbrot_samples(fr, 0.0297908120967462314188, -0.458060975296945872);
if (fr->frac->frac_type == 1 && key == 20)
mandelbrot_samples(fr, 0.471844506346038136365, -1.1151425080399373598);
}
int key_hook(int keycode, void *fr) int key_hook(int keycode, void *fr)
{ {
if (keycode == 53) if (keycode == 53)
quit(fr); quit(fr);
if (keycode == 24)
zoom_in_key(fr);
if (keycode == 27)
zoom_out_key(fr);
if (keycode == 49) if (keycode == 49)
gradient_hook(fr); gradient_hook(fr);
if (keycode == 124)
move_left(fr);
if (keycode == 123) if (keycode == 123)
move_left(fr);
if (keycode == 124)
move_right(fr); move_right(fr);
if (keycode == 125)
move_up(fr);
if (keycode == 126) if (keycode == 126)
move_up(fr);
if (keycode == 125)
move_down(fr); move_down(fr);
if (keycode == 69) if (keycode == 69)
change_limit_up(fr); change_limit_up(fr);
if (keycode == 78) if (keycode == 78)
change_limit_down(fr); change_limit_down(fr);
if (keycode == 18 || keycode == 19 || keycode == 20)
sample(fr, keycode);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */ /* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/24 19:21:45 by gtertysh #+# #+# */ /* Created: 2017/03/24 19:21:45 by gtertysh #+# #+# */
/* Updated: 2017/03/24 19:21:46 by gtertysh ### ########.fr */ /* Updated: 2017/03/25 15:02:31 by gtertysh ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -29,7 +29,7 @@ int change_imagianry(t_fractol *fr, int x, int *start_x)
{ {
if (fr->frac->com_const.im < 3) if (fr->frac->com_const.im < 3)
{ {
fr->frac->com_const.im += 0.01; fr->frac->com_const.im += 0.1;
to_render = 1; to_render = 1;
} }
*start_x = x; *start_x = x;
@ -71,3 +71,19 @@ int change_real(t_fractol *fr, int x, int *start_x)
} }
return (to_render); return (to_render);
} }
void zoom_in_key(t_fractol *fr)
{
fr->frac->mov.z *= 1.5;
new_and_clear_image(fr);
parallel_fractal(fr);
mlx_put_image_to_window(fr->mlx, fr->win, fr->img->ptr, 0, 0);
}
void zoom_out_key(t_fractol *fr)
{
fr->frac->mov.z /= 1.5;
new_and_clear_image(fr);
parallel_fractal(fr);
mlx_put_image_to_window(fr->mlx, fr->win, fr->img->ptr, 0, 0);
}