Skip to content

Commit

Permalink
checks ok
Browse files Browse the repository at this point in the history
  • Loading branch information
DjoykeAbyah committed May 22, 2023
1 parent 28c52d2 commit c2221be
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: djoyke <[email protected]> +#+ #
# +#+ #
# Created: 2023/05/20 15:38:33 by djoyke #+# #+# #
# Updated: 2023/05/22 17:07:49 by dreijans ######## odam.nl #
# Updated: 2023/05/22 20:00:19 by dreijans ######## odam.nl #
# #
# **************************************************************************** #

Expand Down
99 changes: 57 additions & 42 deletions checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,88 @@
/* +:+ */
/* By: dreijans <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/05/02 18:53:37 by dreijans #+# #+# */
/* Updated: 2023/05/22 17:14:56 by dreijans ######## odam.nl */
/* Created: 2023/05/22 17:17:58 by dreijans #+# #+# */
/* Updated: 2023/05/22 20:02:10 by dreijans ######## odam.nl */
/* */
/* ************************************************************************** */

#include "fractol.h"

//checks if strings contain only digits
void digit_check(char **argv)
int ft_is_dot(char *argv)
{
int i;
int j;
int x;

i = 2;
j = 0;
i = 0;
x = 0;
while (argv[i])
{
while (ft_isdigit(argv[i][j]))
{
if (!ft_isdigit(argv[i][j]))
ft_exit("please input correct numbers", 1);
j++;
}
if (argv[i] == '.')
x++;
i++;
}
return (x);
}

//checks for multiple -'s and +'s
void ft_minus_plus_check(char **argv)
int ft_sign(char *argv)
{
int i;
int j;
int x;

i = 2;
j = 0;
i = 0;
x = 0;
while (argv[i])
{
if (argv[i][j] == '-' && argv[i][j + 1] == '-')
ft_exit("please input correct numbers", 1);
if (argv[i][j] == '+' && argv[i][j + 1] == '+')
ft_exit("please input correct numbers", 1);
if (argv[i] == '-' || argv[i] == '+')
x++;
i++;
}
return (x);
}

int ft_sign_dot_num(char *argv)
{
int i;

i = 0;
while (argv[i])
{
if (argv[i] == '.')
i++;
if (i == 0 && (argv[i] == '-' || argv[i] == '+'))
i++;
if (ft_isdigit(argv[i]))
i++;
else
return (0);
}
return (1);
}

// stringinput checken op digits
void ft_string_check(char **argv)
void ft_string_check(char *argv)
{
int i;
int j;
int dot;
int sign;

i = 2;
j = 0;
digit_check(argv);
ft_minus_plus_check(argv);
while (argv[i] != NULL)
i = 0;
dot = ft_is_dot(argv);
sign = ft_sign(argv);
while (argv[i])
{
j = 0;
while (argv[i][j] != '\0')
{
if (!ft_isdigit(argv[i][j]))
{
if ((argv[i][j] == '-' || argv[i][j] == '+'))
j++;
if (argv[i][j] == '.' && !ft_isdigit(argv[i][j + 1]))
ft_exit("please input correct numbers", 1);
ft_exit("please input correct numbers", 1);
}
j++;
}
if (dot > 1)
ft_exit("input number 1", 1);
if (sign > 1)
ft_exit("input number 2", 1);
if (argv[i] == '.' && !ft_isdigit(argv[i + 1]))
ft_exit("input number 3", 1);
if ((argv[i] == '-' || argv[i] == '+') && !ft_isdigit(argv[i + 1]))
ft_exit("intput number 4", 1);
if (!ft_sign_dot_num(argv))
ft_exit("input number 5", 1);
i++;
}
}
Expand All @@ -89,7 +101,10 @@ void check_input(int argc, char **argv, t_fractol *data)
if (argc != 4 && data->fractol == 2)
ft_exit("please try ./fractol julia nbr nbr", 1);
if (argc == 4)
arg_julia(argv, data);
{
ft_string_check(argv[2]);
ft_string_check(argv[3]);
}
if (argc == 4)
ft_string_check(argv);
arg_julia(argv, data);
}
11 changes: 4 additions & 7 deletions fractol.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: dreijans <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/05/01 15:57:11 by dreijans #+# #+# */
/* Updated: 2023/05/22 17:17:21 by dreijans ######## odam.nl */
/* Updated: 2023/05/22 19:49:52 by dreijans ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -17,7 +17,6 @@
# include <stdlib.h>
# include <stdbool.h>
# include <MLX42/MLX42.h>
# include <stdio.h>

// double x[2]; [0]begin + [1]end x
// double y[2]; [0]begin + [1]end y
Expand All @@ -43,17 +42,15 @@ void ft_move(void *param);
double ft_atod(const char *str);
void mandelbrot(t_fractol *data);
void julia(t_fractol *data);
void ft_scroll(double x, double y, void *param);
void ft_zoom(double x, double y, void *param);
void init(t_fractol *fractol, char **argv);
void choose(t_fractol *fractol);
void ft_mouse_pos(t_fractol *data);
void ft_travel(t_fractol *data);
void ft_zoom(t_fractol *data);
void ft_iter(t_fractol *data);
void check_input(int argc, char **argv, t_fractol *data);
void arg_julia(char **argv, t_fractol *data);
void ft_string_check(char **argv);
void ft_minus_plus_check(char **argv);
// void ft_color(t_fractol *data);
void ft_string_check(char *argv);
void ft_exit(char *s, int fd);

#endif
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: dreijans <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/05/01 15:42:21 by dreijans #+# #+# */
/* Updated: 2023/05/22 17:05:41 by dreijans ######## odam.nl */
/* Updated: 2023/05/22 19:58:52 by dreijans ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -30,7 +30,7 @@ int main(int argc, char **argv)
return (EXIT_FAILURE);
choose(&fractol);
mlx_loop_hook(fractol.mlx, ft_move, &fractol);
mlx_scroll_hook(fractol.mlx, ft_scroll, &fractol);
mlx_scroll_hook(fractol.mlx, ft_zoom, &fractol);
mlx_loop(fractol.mlx);
mlx_terminate(fractol.mlx);
return (EXIT_SUCCESS);
Expand Down
18 changes: 6 additions & 12 deletions navigate.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
/* By: dreijans <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/05/20 18:50:12 by dreijans #+# #+# */
/* Updated: 2023/05/22 14:49:36 by djoyke ######## odam.nl */
/* Updated: 2023/05/22 19:57:43 by dreijans ######## odam.nl */
/* */
/* ************************************************************************** */

#include "fractol.h"

//event triggered function
//if statement alleen if key is pressed, checks every frame
void ft_move(void *param)
{
t_fractol *data;
Expand All @@ -22,7 +21,7 @@ void ft_move(void *param)
if (mlx_is_key_down(data->mlx, MLX_KEY_ESCAPE))
mlx_close_window(data->mlx);
ft_travel(data);
ft_zoom(data);
ft_iter(data);
if (mlx_is_mouse_down(data->mlx, MLX_MOUSE_BUTTON_RIGHT))
{
ft_mouse_pos(data);
Expand All @@ -31,8 +30,7 @@ void ft_move(void *param)
}

//increasing or decreasing iterations
//need to change this name
void ft_zoom(t_fractol *data)
void ft_iter(t_fractol *data)
{
if (mlx_is_key_down(data->mlx, MLX_KEY_EQUAL))
{
Expand Down Expand Up @@ -75,11 +73,8 @@ void ft_travel(t_fractol *data)
}
}

//y > 0 is bigger
//y < 0 is smaller
//save pos of the mouse to use later
//try zooming centre of current window
void ft_scroll(double x, double y, void *param)
//zooming centre of current window
void ft_zoom(double x, double y, void *param)
{
t_fractol *data;

Expand All @@ -102,8 +97,7 @@ void ft_scroll(double x, double y, void *param)
choose(data);
}

//pixels veranderen naar cooordinaten
//can use mouse pos func for zoom
//pixels to coordinates
void ft_mouse_pos(t_fractol *data)
{
int32_t x;
Expand Down
31 changes: 1 addition & 30 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: dreijans <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/05/16 18:06:21 by dreijans #+# #+# */
/* Updated: 2023/05/22 17:15:07 by dreijans ######## odam.nl */
/* Updated: 2023/05/22 17:19:44 by dreijans ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -80,32 +80,3 @@ void ft_exit(char *s, int fd)
ft_putchar_fd('\n', fd);
exit(EXIT_FAILURE);
}

// void ft_color(t_fractol *data)
// {
// if (mlx_is_key_down(data->mlx, MLX_KEY_R))
// {
// //color is changed in more R hues
// printf("R\n");
// choose(data);
// }
// if (mlx_is_key_down(data->mlx, MLX_KEY_B))
// {
// // color is changed in more B hues
// printf("B\n");
// choose(data);
// }
// if (mlx_is_key_down(data->mlx, MLX_KEY_G))
// {
// // color is changed in more G hues
// printf("G\n");
// choose(data);
// }
// if (mlx_is_key_down(data->mlx, MLX_KEY_A))
// {
// // color is changed in more or less opacity
// printf("A\n");
// choose(data);
// }
// }

0 comments on commit c2221be

Please sign in to comment.