Compare commits
No commits in common. "02fe8897ee4c5bf496feef57af2749e3b9ef9edf" and "b399898721b8b748cda35f7548a5fc085ca80443" have entirely different histories.
02fe8897ee
...
b399898721
11 changed files with 135 additions and 215 deletions
29
CMakeLists.txt
Normal file
29
CMakeLists.txt
Normal file
|
@ -0,0 +1,29 @@
|
|||
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
|
4
Makefile
4
Makefile
|
@ -6,7 +6,7 @@
|
|||
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2016/12/14 16:54:48 by gtertysh #+# #+# #
|
||||
# Updated: 2017/03/25 17:59:43 by gtertysh ### ########.fr #
|
||||
# Updated: 2017/03/24 13:59:39 by gtertysh ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
@ -102,7 +102,7 @@ libclean:
|
|||
@make clean -s -C $(LIBFT_DIR)
|
||||
@make clean -s -C $(MLX_DIR)
|
||||
|
||||
libfclean: libclean
|
||||
libfclean:
|
||||
@make fclean -s -C $(LIBFT_DIR)
|
||||
|
||||
re: fclean libfclean all
|
||||
|
|
1
author
1
author
|
@ -1 +0,0 @@
|
|||
gtertysh
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 20:59:04 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/25 17:36:38 by gtertysh ### ########.fr */
|
||||
/* Updated: 2017/03/24 14:00:01 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -16,8 +16,10 @@
|
|||
# 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
|
||||
|
@ -38,6 +40,7 @@
|
|||
|
||||
# define NUM_THREADS 24
|
||||
|
||||
|
||||
typedef struct s_complex
|
||||
{
|
||||
long double rl;
|
||||
|
@ -83,14 +86,14 @@ typedef struct s_image
|
|||
int bpp;
|
||||
} t_image;
|
||||
|
||||
typedef t_color (*t_frac_func)(t_frac_data *data, int x, int y);
|
||||
typedef t_color (*frac_func)(t_frac_data *data, int x, int y);
|
||||
|
||||
typedef struct s_fractol
|
||||
{
|
||||
void *mlx;
|
||||
void *win;
|
||||
t_frac_data *frac;
|
||||
t_frac_func fr_funcs[3];
|
||||
frac_func fr_funcs[3];
|
||||
int w_height;
|
||||
int w_width;
|
||||
t_image *img;
|
||||
|
@ -101,7 +104,7 @@ typedef struct s_thread_data
|
|||
t_fractol fr;
|
||||
int y_start;
|
||||
int y_end;
|
||||
t_frac_func fractal_func;
|
||||
frac_func fractal_func;
|
||||
} t_thread_data;
|
||||
|
||||
void quit(t_fractol *fractol);
|
||||
|
@ -134,8 +137,6 @@ 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);
|
||||
|
@ -147,7 +148,4 @@ 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
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 19:13:25 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/24 20:06:06 by gtertysh ### ########.fr */
|
||||
/* Updated: 2016/12/06 19:47:50 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/28 18:15:15 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/24 20:41:17 by gtertysh ### ########.fr */
|
||||
/* Created: 2016/12/04 15:59:21 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:45:44 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_fd *new_node(int fd)
|
||||
static t_fd *new_node(int fd)
|
||||
{
|
||||
t_fd *new;
|
||||
|
||||
|
@ -27,7 +27,7 @@ t_fd *new_node(int fd)
|
|||
return (new);
|
||||
}
|
||||
|
||||
t_fd *find_fd(int fd, t_fd **cur_fd)
|
||||
static t_fd *find_fd(int fd, t_fd **cur_fd)
|
||||
{
|
||||
if (!*cur_fd)
|
||||
return ((*cur_fd = new_node(fd)));
|
||||
|
@ -40,59 +40,6 @@ t_fd *find_fd(int fd, t_fd **cur_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)
|
||||
{
|
||||
static t_fd *head_fd;
|
||||
|
@ -103,11 +50,27 @@ int get_next_line(const int fd, char **line)
|
|||
*line = ft_strnew(0);
|
||||
c = find_fd(fd, &head_fd);
|
||||
c->readed = 0;
|
||||
if (check_reminder(c, line))
|
||||
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);
|
||||
if (check_buf(c, line) == -1)
|
||||
return (-1);
|
||||
if ((c->readed == 0) && !ft_strlen(*line))
|
||||
}
|
||||
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);
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 12:21:43 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/24 20:05:11 by gtertysh ### ########.fr */
|
||||
/* Updated: 2016/12/27 18:02:00 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/24 19:37:32 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/25 17:35:04 by gtertysh ### ########.fr */
|
||||
/* Updated: 2017/03/24 19:37:33 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;
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
32
src/hooks.c
32
src/hooks.c
|
@ -6,52 +6,30 @@
|
|||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/16 18:59:03 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/25 14:59:09 by gtertysh ### ########.fr */
|
||||
/* Updated: 2017/03/24 14:02:46 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 == 123)
|
||||
move_left(fr);
|
||||
if (keycode == 124)
|
||||
move_left(fr);
|
||||
if (keycode == 123)
|
||||
move_right(fr);
|
||||
if (keycode == 126)
|
||||
move_up(fr);
|
||||
if (keycode == 125)
|
||||
move_up(fr);
|
||||
if (keycode == 126)
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/24 19:21:45 by gtertysh #+# #+# */
|
||||
/* Updated: 2017/03/25 15:02:31 by gtertysh ### ########.fr */
|
||||
/* Updated: 2017/03/24 19:21:46 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.1;
|
||||
fr->frac->com_const.im += 0.01;
|
||||
to_render = 1;
|
||||
}
|
||||
*start_x = x;
|
||||
|
@ -71,19 +71,3 @@ 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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue