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> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# 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 $(MLX_DIR)
libfclean:
libfclean: libclean
@make fclean -s -C $(LIBFT_DIR)
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> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 "mlx.h"
# include <math.h>
# include <fcntl.h>
# include <pthread.h>
# include <time.h>
# include <unistd.h>
# define HEIGHT 700
# define WIDTH 1300
@ -40,85 +38,84 @@
# define NUM_THREADS 24
typedef struct s_complex
typedef struct s_complex
{
long double rl;
long double im;
long double im;
} t_complex;
typedef struct s_move
typedef struct s_move
{
long double x;
long double y;
long double z;
} t_move;
typedef struct s_color
typedef struct s_color
{
int red;
int grn;
int blu;
int red;
int grn;
int blu;
} t_color;
typedef struct s_gradient
typedef struct s_gradient
{
t_color grd[NUM_COLORS];
t_color grd[NUM_COLORS];
} t_gradient;
typedef struct s_frac_data
typedef struct s_frac_data
{
t_complex com_const;
t_gradient grd;
t_move mov;
int max_itr;
int com_rl_im_change;
int allow_mouse_change;
int frac_type;
int max_itr;
int com_rl_im_change;
int allow_mouse_change;
int frac_type;
} t_frac_data;
typedef struct s_image
typedef struct s_image
{
void *ptr;
char *data;
int l_size;
int end;
int bpp;
int bpp;
} 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
{
void *mlx;
void *win;
t_frac_data *frac;
frac_func fr_funcs[3];
t_frac_func fr_funcs[3];
int w_height;
int w_width;
t_image *img;
} t_fractol;
typedef struct s_thread_data
typedef struct s_thread_data
{
t_fractol fr;
int y_start;
int y_end;
frac_func fractal_func;
int y_start;
int y_end;
t_frac_func fractal_func;
} t_thread_data;
void quit(t_fractol *fractol);
void print_help(void);
void parse_input(int ac, char **av);
t_color gradient(float value, t_gradient gradient);
t_color gradient(float value, t_gradient gradient);
t_gradient default_gradient(void);
t_gradient random_gradient(void);
t_fractol *fractol_init(void *mlx, int frac_type);
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);
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_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_right(t_fractol *fr);
void move_up(t_fractol *fr);
@ -144,8 +143,11 @@ void move_down(t_fractol *fr);
void reset(t_fractol *fr);
void change_limit_down(t_fractol *fr);
void change_limit_up(t_fractol *fr);
int change_real(t_fractol *fr, int x, int *start_x);
int change_imagianry(t_fractol *fr, int x, int *start_x);
int change_real(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 julia_samples(t_fractol *fr, double real, double img);
void mandelbrot_samples(t_fractol *fr, double x, double y);
#endif

View file

@ -6,7 +6,7 @@
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
@ -23,4 +23,4 @@ int ft_lst_len(t_list *lst)
len++;
}
return (len);
}
}

View file

@ -5,72 +5,109 @@
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/04 15:59:21 by gtertysh #+# #+# */
/* Updated: 2016/12/06 19:45:44 by gtertysh ### ########.fr */
/* Created: 2017/01/28 18:15:15 by gtertysh #+# #+# */
/* Updated: 2017/03/24 20:41:17 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static t_fd *new_node(int fd)
t_fd *new_node(int fd)
{
t_fd *new;
t_fd *new;
new = NULL;
if ((new = (t_fd *)malloc(sizeof(t_fd))))
{
new->fd = fd;
new->n = NULL;
new->next = NULL;
new->t = 0;
}
return (new);
new = NULL;
if ((new = (t_fd *)malloc(sizeof(t_fd))))
{
new->fd = fd;
new->n = NULL;
new->next = NULL;
new->t = 0;
}
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)
return ((*cur_fd = new_node(fd)));
while ((*cur_fd))
{
if ((*cur_fd)->fd == fd)
return (*cur_fd);
cur_fd = &((*cur_fd)->next);
}
return ((*cur_fd = new_node(fd)));
if (!*cur_fd)
return ((*cur_fd = new_node(fd)));
while ((*cur_fd))
{
if ((*cur_fd)->fd == fd)
return (*cur_fd);
cur_fd = &((*cur_fd)->next);
}
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)
{
static t_fd *head_fd;
t_fd *c;
static t_fd *head_fd;
t_fd *c;
if (fd < 0 || !line)
return (-1);
*line = ft_strnew(0);
c = find_fd(fd, &head_fd);
c->readed = 0;
if (c->n) {
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);
}
else if ((*line = ft_strjoin(*line, c->n)))
{
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 (1);
}
if (fd < 0 || !line)
return (-1);
*line = ft_strnew(0);
c = find_fd(fd, &head_fd);
c->readed = 0;
if (check_reminder(c, line))
return (1);
if (check_buf(c, line) == -1)
return (-1);
if ((c->readed == 0) && !ft_strlen(*line))
return (0);
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */
@ -19,15 +19,15 @@
# define BUFF_SIZE 640000
typedef struct s_fd
typedef struct s_fd
{
int fd;
char b[BUFF_SIZE + 1];
char *n;
struct s_fd *next;
char *t;
int readed;
} t_fd;
int fd;
char b[BUFF_SIZE + 1];
char *n;
struct s_fd *next;
char *t;
int readed;
} t_fd;
typedef struct s_list
{

View file

@ -6,7 +6,7 @@
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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
complex_equal(0, 0, &f->com_const);
f->com_rl_im_change = 1;
f->allow_mouse_change = -1;
f->allow_mouse_change = 1;
f->mov.x = 0;
f->mov.y = 0;
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> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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"
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)
{
if (keycode == 53)
quit(fr);
if (keycode == 24)
zoom_in_key(fr);
if (keycode == 27)
zoom_out_key(fr);
if (keycode == 49)
gradient_hook(fr);
if (keycode == 124)
move_left(fr);
if (keycode == 123)
move_left(fr);
if (keycode == 124)
move_right(fr);
if (keycode == 125)
move_up(fr);
if (keycode == 126)
move_up(fr);
if (keycode == 125)
move_down(fr);
if (keycode == 69)
change_limit_up(fr);
if (keycode == 78)
change_limit_down(fr);
if (keycode == 18 || keycode == 19 || keycode == 20)
sample(fr, keycode);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)
{
fr->frac->com_const.im += 0.01;
fr->frac->com_const.im += 0.1;
to_render = 1;
}
*start_x = x;
@ -71,3 +71,19 @@ int change_real(t_fractol *fr, int x, int *start_x)
}
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);
}