42_solong/color.c
2023-01-08 18:03:40 +01:00

59 lines
2.1 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/08 15:56:19 by cchauvet #+# #+# */
/* Updated: 2023/01/08 17:51:40 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "solong.h"
static int ft_textures_set(t_data *data, char **colors)
{
t_square square;
if (data->nb_color_swap + 5 > NB_COLORS)
data->nb_color_swap = 0;
square.color = colors[data->nb_color_swap++];
data->ecolor = name_generator(square);
square.color = colors[data->nb_color_swap++];
data->pcolor = name_generator(square);
square.color = colors[data->nb_color_swap++];
data->wcolor = name_generator(square);
square.color = colors[data->nb_color_swap++];
data->ccolor = name_generator(square);
square.color = colors[data->nb_color_swap++];
square.size = WINDOW_SIZE;
square.color = colors[data->nb_color_swap++];
data->bcolor = name_generator(square);
if (data->bcolor == NULL || data->wcolor == NULL
|| data->pcolor == NULL || data->ecolor == NULL || data->ccolor == NULL)
{
ft_printf("Memory error");
ft_freer_ultimate(5, data->wcolor, data->ecolor, data->bcolor);
ft_freer_ultimate(2, data->pcolor, data->ccolor);
return (1);
}
return (0);
}
int ft_color_changer(t_data *data)
{
char **colors;
colors = ft_split(COLORS, '|');
if (colors == NULL)
{
ft_printf("Memory error");
return (1);
}
ft_textures_set(data, colors);
ft_freer_tab_ultimate(1, colors);
return (0);
}