mirror of
https://github.com/Ladebeze66/fractol.git
synced 2025-12-13 04:37:07 +01:00
fractol
This commit is contained in:
commit
81dabf31f5
116
Makefile
Executable file
116
Makefile
Executable file
@ -0,0 +1,116 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/09/08 15:58:04 by fgras-ca #+# #+# #
|
||||
# Updated: 2023/09/09 18:35:45 by ladebeze ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
|
||||
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
|
||||
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
|
||||
echo "( ( ( ( ( ( ( ("
|
||||
|
||||
DEF_COLOR = \033[0m
|
||||
GRAY = \033[0;90m
|
||||
RED = \033[0;91m
|
||||
GREEN = \033[0;92m
|
||||
YELLOW = \033[0;93m
|
||||
BLUE = \033[0;94m
|
||||
MAGENTA = \033[0;95m
|
||||
CYAN = \033[0;96m
|
||||
WHITE = \033[0;97m
|
||||
ORANGE = \033[38;5;214m
|
||||
|
||||
NAME = fractol
|
||||
NAME_BONUS = fractol_b
|
||||
LIBFT = libft.a
|
||||
MINILIB = libmlx.a
|
||||
|
||||
SRC = fractol.c \
|
||||
check_arguments.c \
|
||||
fractol_utils.c \
|
||||
hook.c \
|
||||
julia.c \
|
||||
mandelbrot.c \
|
||||
color.c \
|
||||
|
||||
SRC_BONUS = fractol_bonus.c \
|
||||
check_arguments_bonus.c \
|
||||
fractol_utils_bonus.c \
|
||||
hook_bonus.c \
|
||||
julia_bonus.c \
|
||||
mandelbrot_bonus.c \
|
||||
burning_bonus.c \
|
||||
color_bonus.c \
|
||||
|
||||
SRC_DIR_LIBFT = libft/
|
||||
SRC_DIR_MINILIB = minilibx-linux/
|
||||
SRC_LIBFT = $(addprefix $(SRC_DIR_LIBFT), $(LIBFT))
|
||||
SRC_MINILIB = $(addprefix $(SRC_DIR_MINILIB), $(MINILIB))
|
||||
|
||||
OBJS = ${SRC:.c=.o}
|
||||
OBJSB = ${SRC_BONUS:.c=.o}
|
||||
CC = cc
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
MLX = -lX11 -lXext -lXrandr -lm
|
||||
RM = rm -f
|
||||
|
||||
all : $(NAME)
|
||||
|
||||
$(NAME) : $(OBJS)
|
||||
@echo "$(RED)Loading minilibX... $(DEF_COLOR)"
|
||||
@make -C minilibx-linux
|
||||
@echo "$(GREEN)minilibX...Done. $(DEF_COLOR)"
|
||||
@echo "$(RED)Loading Libft... $(DEF_COLOR)"
|
||||
@make -C libft
|
||||
@echo "$(GREEN)Libft...Done. $(DEF_COLOR)"
|
||||
@echo "$(RED)Compilation fractol... $(DEF_COLOR)"
|
||||
$(CC) $(CFLAGS) $(OBJS) $(SRC_MINILIB) $(SRC_LIBFT) $(MLX) -o $(NAME)
|
||||
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./fractol" for the menu!!$(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
bonus : $(NAME_BONUS)
|
||||
|
||||
$(NAME_BONUS) : $(OBJSB)
|
||||
@echo "$(RED)Loading minilibX... $(DEF_COLOR)"
|
||||
@make -C minilibx-linux
|
||||
@echo "$(GREEN)minilibX...Done. $(DEF_COLOR)"
|
||||
@echo "$(RED)Loading Libft... $(DEF_COLOR)"
|
||||
@make -C libft
|
||||
@echo "$(GREEN)Libft...Done. $(DEF_COLOR)"
|
||||
@echo "$(RED)Compilation fractol with bonus... $(DEF_COLOR)"
|
||||
$(CC) $(CFLAGS) $(OBJSB) $(SRC_MINILIB) $(SRC_LIBFT) $(MLX) -o $(NAME_BONUS)
|
||||
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./fractol_b" for the menu!!$(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
clean :
|
||||
@echo "$(RED)Cleaning Libft... $(DEF_COLOR)"
|
||||
@make -C libft clean
|
||||
@echo "$(GREEN)Libft cleaned!! $(DEF_COLOR)"
|
||||
@echo "$(RED)Cleaning MinilibX... $(DEF_COLOR)"
|
||||
@make -C minilibx-linux clean
|
||||
@echo "$(GREEN)MinilibX cleaned!! $(DEF_COLOR)"
|
||||
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
|
||||
$(RM) $(OBJS) $(OBJSB)
|
||||
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
fclean : clean
|
||||
@echo "$(RED)fclean Libft... $(DEF_COLOR)"
|
||||
@make -C ./libft fclean
|
||||
@echo "$(GREEN)Libft cleaned!! $(DEF_COLOR)"
|
||||
@echo "$(RED)Delete program name... $(DEF_COLOR)"
|
||||
$(RM) $(NAME) $(NAME_BONUS)
|
||||
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
re : fclean all
|
||||
|
||||
rebonus : fclean bonus
|
||||
|
||||
.PHONY : all bonus clean fclean re rebonus
|
||||
59
burning_bonus.c
Executable file
59
burning_bonus.c
Executable file
@ -0,0 +1,59 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* burning_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:55:21 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:56:11 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol_bonus.h"
|
||||
|
||||
static int set_burning(double x, double y)
|
||||
{
|
||||
double xz;
|
||||
double yz;
|
||||
double temp;
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
xz = x;
|
||||
yz = y;
|
||||
while ((xz * xz + yz * yz <= 4) && (i < MAX_ITER))
|
||||
{
|
||||
i ++;
|
||||
temp = xz;
|
||||
xz = (xz * xz) - (yz * yz) - x;
|
||||
yz = fabs(2 * temp * yz) - y;
|
||||
}
|
||||
if (i == MAX_ITER)
|
||||
return (0);
|
||||
return (i);
|
||||
}
|
||||
|
||||
void burning(t_fractol *fractol)
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
|
||||
fractol->x = 0;
|
||||
fractol->y = 0;
|
||||
while (fractol->y <= IMG_Y)
|
||||
{
|
||||
while (fractol->x <= IMG_X)
|
||||
{
|
||||
x = fractol->x_min + \
|
||||
(fractol->x * ((fractol->x_max - fractol->x_min) / IMG_X));
|
||||
y = fractol->y_max - \
|
||||
(fractol->y * ((fractol->y_max - fractol->y_min) / IMG_Y));
|
||||
my_img_pixel_put(fractol, fractol->x, fractol->y, \
|
||||
color(set_burning(x, y), fractol));
|
||||
fractol->x++;
|
||||
}
|
||||
fractol->x = 0;
|
||||
fractol->y ++;
|
||||
}
|
||||
}
|
||||
72
check_arguments.c
Executable file
72
check_arguments.c
Executable file
@ -0,0 +1,72 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_arguments.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:41:03 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 17:07:36 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
static void message(void)
|
||||
{
|
||||
ft_putstr_fd(RED "THE ARGUMENTS ARE WRONG!!!\n", 1);
|
||||
ft_putstr_fd(BLUE "\nFor execute the program :", 1);
|
||||
ft_putstr_fd(ORANGE "\nPlease type : ./fractol mandelbrot", 1);
|
||||
ft_putstr_fd("\nOr : ./fractol julia x.xxx x.xxx\n", 1);
|
||||
ft_putstr_fd(GREEN "\nWhere x represents digit", 1);
|
||||
ft_putstr_fd("\nExample: ./fractol julia -0.4 0.6\n", 1);
|
||||
ft_putstr_fd(YELLOW "\nYOU CAN ZOOM WHITH MOUSE WHELL\n", 1);
|
||||
ft_putstr_fd(CYAN "\nESC FOR QUIT THE PROGRAM!!\n" DEF_COLOR, 1);
|
||||
}
|
||||
|
||||
static int check_number(char *nbr)
|
||||
{
|
||||
int index;
|
||||
int point;
|
||||
|
||||
point = 0;
|
||||
index = 0;
|
||||
if (nbr[index] == '+' || nbr[index] == '-')
|
||||
index ++;
|
||||
if (nbr[index] == '.' || !nbr[index])
|
||||
return (0);
|
||||
while (nbr[index])
|
||||
{
|
||||
if (ft_isdigit(nbr[index]) == 0)
|
||||
{
|
||||
if (nbr[index] != '.' || point > 0 || !nbr[index +1])
|
||||
return (0);
|
||||
point ++;
|
||||
}
|
||||
index ++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int check_arguments(int argc, char **argv)
|
||||
{
|
||||
if (argc == 2)
|
||||
{
|
||||
if (ft_strncmp ("mandelbrot", argv[1], ft_strlen ("mandelbrot")) == 0)
|
||||
return (1);
|
||||
message ();
|
||||
return (0);
|
||||
}
|
||||
if (argc == 4)
|
||||
{
|
||||
if (ft_strncmp("julia", argv[1], ft_strlen ("julia")) == 0)
|
||||
{
|
||||
if (check_number (argv[2]) != 0 && check_number (argv[3]) != 0)
|
||||
return (1);
|
||||
}
|
||||
message ();
|
||||
return (0);
|
||||
}
|
||||
message ();
|
||||
return (0);
|
||||
}
|
||||
77
check_arguments_bonus.c
Executable file
77
check_arguments_bonus.c
Executable file
@ -0,0 +1,77 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* check_arguments_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:43:42 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 17:06:52 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol_bonus.h"
|
||||
|
||||
static void message(void)
|
||||
{
|
||||
ft_putstr_fd(RED "THE ARGUMENTS ARE WRONG!!!\n", 1);
|
||||
ft_putstr_fd(BLUE "\nFor execute the bonus version:", 1);
|
||||
ft_putstr_fd(ORANGE "\nPlease type : ./fractol mandelbrot", 1);
|
||||
ft_putstr_fd("\nOr : ./fractol julia x.xxx x.xxx\n", 1);
|
||||
ft_putstr_fd(GREEN "\nWhere x represents digit", 1);
|
||||
ft_putstr_fd("\nExample: ./fractol julia -0.4 0.6\n", 1);
|
||||
ft_putstr_fd(ORANGE "\nBurning for display the bonus Burning Ship\n", 1);
|
||||
ft_putstr_fd(YELLOW "\nZOOM MOUSE WHELL(follow mouse)\n" DEF_COLOR, 1);
|
||||
ft_putstr_fd(YELLOW "\nYou can change color with 'A' 'S' 'D'\n", 1);
|
||||
ft_putstr_fd(YELLOW "\nMove the picture with keyboard arrows!!\n", 1);
|
||||
ft_putstr_fd(CYAN "\nESC FOR QUIT THE PROGRAM!!\n" DEF_COLOR, 1);
|
||||
}
|
||||
|
||||
static int check_number(char *nbr)
|
||||
{
|
||||
int index;
|
||||
int point;
|
||||
|
||||
point = 0;
|
||||
index = 0;
|
||||
if (nbr[index] == '+' || nbr[index] == '-')
|
||||
index ++;
|
||||
if (nbr[index] == '.' || !nbr[index])
|
||||
return (0);
|
||||
while (nbr[index])
|
||||
{
|
||||
if (ft_isdigit(nbr[index]) == 0)
|
||||
{
|
||||
if (nbr[index] != '.' || point > 0 || !nbr[index +1])
|
||||
return (0);
|
||||
point ++;
|
||||
}
|
||||
index ++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int check_arguments(int argc, char **argv)
|
||||
{
|
||||
if (argc == 2)
|
||||
{
|
||||
if (ft_strncmp ("mandelbrot", argv[1], ft_strlen ("mandelbrot")) == 0)
|
||||
return (1);
|
||||
if (ft_strncmp ("burning", argv[1], ft_strlen ("burning")) == 0)
|
||||
return (1);
|
||||
message ();
|
||||
return (0);
|
||||
}
|
||||
if (argc == 4)
|
||||
{
|
||||
if (ft_strncmp("julia", argv[1], ft_strlen ("julia")) == 0)
|
||||
{
|
||||
if (check_number (argv[2]) != 0 && check_number (argv[3]) != 0)
|
||||
return (1);
|
||||
}
|
||||
message ();
|
||||
return (0);
|
||||
}
|
||||
message ();
|
||||
return (0);
|
||||
}
|
||||
20
color.c
Executable file
20
color.c
Executable file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* color.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:47:04 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:47:34 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
int color(int i, t_fractol *fractol)
|
||||
{
|
||||
if (fractol->color == 1)
|
||||
return (i * 0x00ABCDEF);
|
||||
return (0);
|
||||
}
|
||||
35
color_bonus.c
Executable file
35
color_bonus.c
Executable file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* color_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:48:10 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:48:36 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol_bonus.h"
|
||||
|
||||
int color(int i, t_fractol *fractol)
|
||||
{
|
||||
if (fractol->color == 1)
|
||||
return (i * 0x00ABCDEF);
|
||||
if (fractol->color == 2)
|
||||
return (i * 0x00FEDCBA);
|
||||
if (fractol->color == 3)
|
||||
return (i * 0x00ABCABC);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void change_color(int keycode, t_fractol *fractol)
|
||||
{
|
||||
if (keycode == 97)
|
||||
fractol->color = 1;
|
||||
else if (keycode == 115)
|
||||
fractol->color = 2;
|
||||
else if (keycode == 100)
|
||||
fractol->color = 3;
|
||||
choose(fractol);
|
||||
}
|
||||
242
fr.subject.pdf
Normal file
242
fr.subject.pdf
Normal file
@ -0,0 +1,242 @@
|
||||
fract’ol
|
||||
|
||||
Art fractal
|
||||
|
||||
Résumé:
|
||||
Ce projet consiste à créer graphiquement de jolies fractales.
|
||||
|
||||
Version: 3
|
||||
Table des matières
|
||||
|
||||
I Préambule 2
|
||||
|
||||
II Introduction 3
|
||||
|
||||
III Objectifs 4
|
||||
|
||||
IV Règles communes 5
|
||||
|
||||
V Partie obligatoire 6
|
||||
|
||||
V.1 Rendu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
|
||||
|
||||
V.2 Gestion graphique . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
|
||||
|
||||
VI Partie bonus 8
|
||||
|
||||
VII Rendu et peer-evaluation 9
|
||||
|
||||
1
|
||||
Chapitre I
|
||||
|
||||
Préambule
|
||||
|
||||
Voici ce que Wikipedia a à dire sur la fracturation hydraulique :
|
||||
La « fracturation hydraulique » est la dislocation ciblée de formations géologiques
|
||||
peu perméables par le moyen de l’injection sous très haute pression d’un fluide destiné à
|
||||
fissurer et micro-fissurer la roche. Cette fracturation peut être pratiquée à proximité de
|
||||
la surface, ou à grande profondeur (à plus de 1 km, voire à plus de 4 km dans le cas du
|
||||
gaz de schiste), et à partir de puits verticaux, inclinés ou horizontaux.
|
||||
Cette technique relativement ancienne (1947), inventée pour les gisements d’hydrocar-
|
||||
bures conventionnels, a vu son intérêt renouvelé par son association au forage horizontal
|
||||
(développé, lui, à partir de 1980). C’est la maîtrise graduelle de la rentabilité économique
|
||||
de cette association pour les gisements non-conventionnels, qui a guidé le développement
|
||||
récent de l’exploitation de ces derniers : elle a rendu accessibles des ressources autrefois
|
||||
soit inaccessibles, soit qui n’auraient été exploitables qu’à des coûts exorbitants et avec
|
||||
lenteur.
|
||||
Elle est effectuée en fracturant la roche par un « stress » mécanique à l’aide d’un
|
||||
fluide injecté sous haute pression à partir d’un forage de surface, pour en augmenter la
|
||||
macro porosité et moindrement la micro-porosité. Le fluide peut être de l’eau, une boue
|
||||
ou un fluide technique dont la viscosité a été ajustée.
|
||||
Ce projet ne s’appelle pas fract’oil et par conséquence n’a aucun rapport avec la
|
||||
fracturation hydraulique.
|
||||
|
||||
2
|
||||
Chapitre II
|
||||
Introduction
|
||||
|
||||
Créé par Benoît Mandelbrot en 1974 à partir de la racine latine fractus, qui signifie
|
||||
"brisé" , "irrégulier", une figure fractale est un objet mathématique, telle une courbe ou
|
||||
une surface, dont la structure est invariante quelque soit le changement d’échelle.
|
||||
|
||||
De nombreux phénomènes naturels – comme l’aspect du chou romanesco – possèdent
|
||||
des formes fractales approximatives.
|
||||
|
||||
À vous aujourd’hui de vous essayer à cette pratique et de générer de magnifiques
|
||||
fractales !
|
||||
3
|
||||
Chapitre III
|
||||
Objectifs
|
||||
|
||||
Il est temps pour vous d’attaquer votre premier projet graphique !
|
||||
Vous allez maintenant prendre en main la bibliothèque graphique de l’école : la
|
||||
MiniLibX ! Cette bibliothèque a été développée en interne et inclut des outils basiques
|
||||
permettant d’ouvrir une fenêtre, de créer des images et de gérer des événements clavier
|
||||
et souris.
|
||||
Ce nouveau projet sera pour vous l’occasion de débuter dans l’utilisation de la MiniLibX,
|
||||
de découvrir ou d’utiliser la notion mathémathique des nombres complexes, d’aborder
|
||||
la problématique de l’optimisation en programmation graphique, ainsi que la gestion
|
||||
des événements.
|
||||
|
||||
N’oubliez pas de regarder les vidéos sur l’e-learning !
|
||||
|
||||
4
|
||||
Chapitre IV
|
||||
|
||||
Règles communes
|
||||
|
||||
• Votre projet doit être écrit en C.
|
||||
|
||||
• Votre projet doit être codé à la Norme. Si vous avez des fichiers ou fonctions bonus,
|
||||
celles-ci seront inclues dans la vérification de la norme et vous aurez 0 au projet
|
||||
en cas de faute de norme.
|
||||
|
||||
• Vos fonctions ne doivent pas s’arrêter de manière inattendue (segmentation fault,
|
||||
bus error, double free, etc) mis à part dans le cas d’un comportement indéfini. Si
|
||||
cela arrive, votre projet sera considéré non fonctionnel et vous aurez 0 au projet.
|
||||
|
||||
• Toute mémoire allouée sur la heap doit être libéré lorsque c’est nécessaire. Aucun
|
||||
leak ne sera toléré.
|
||||
|
||||
• Si le projet le demande, vous devez rendre un Makefile qui compilera vos sources
|
||||
pour créer la sortie demandée, en utilisant les flags -Wall, -Wextra et -Werror.
|
||||
Votre Makefile ne doit pas relink.
|
||||
|
||||
• Si le projet demande un Makefile, votre Makefile doit au minimum contenir les
|
||||
règles $(NAME), all, clean, fclean et re.
|
||||
|
||||
• Pour rendre des bonus, vous devez inclure une règle bonus à votre Makefile qui
|
||||
ajoutera les divers headers, librairies ou fonctions qui ne sont pas autorisées dans
|
||||
la partie principale du projet. Les bonus doivent être dans un fichier différent :
|
||||
_bonus.{c/h}. L’évaluation de la partie obligatoire et de la partie bonus sont
|
||||
faites séparément.
|
||||
|
||||
• Si le projet autorise votre libft, vous devez copier ses sources et son Makefile
|
||||
associé dans un dossier libft contenu à la racine. Le Makefile de votre projet doit
|
||||
compiler la librairie à l’aide de son Makefile, puis compiler le projet.
|
||||
|
||||
• Nous vous recommandons de créer des programmes de test pour votre projet, bien
|
||||
que ce travail ne sera pas rendu ni noté. Cela vous donnera une chance de
|
||||
tester facilement votre travail ainsi que celui de vos pairs.
|
||||
|
||||
• Vous devez rendre votre travail sur le git qui vous est assigné. Seul le travail déposé
|
||||
sur git sera évalué. Si Deepthought doit corriger votre travail, cela sera fait à la fin
|
||||
des peer-evaluations. Si une erreur se produit pendant l’évaluation Deepthought,
|
||||
celle-ci s’arrête.
|
||||
|
||||
5
|
||||
Chapitre V
|
||||
Partie obligatoire
|
||||
|
||||
Nom du pro- fractol
|
||||
gramme
|
||||
Fichiers de rendu Makefile, *.h, *.c
|
||||
Makefile NAME, all, clean, fclean, re
|
||||
Arguments Le type de fractale à afficher et toute autre
|
||||
option disponible
|
||||
Fonctions ex-
|
||||
• open, close, read, write,
|
||||
ternes autorisées malloc, free, perror,
|
||||
strerror, exit
|
||||
|
||||
• Toutes les fonctions de la
|
||||
bibliothèque mathématique
|
||||
(option de compilation -lm,
|
||||
man man 3 math)
|
||||
|
||||
• Toutes les fonctions de la
|
||||
MiniLibX
|
||||
|
||||
• ft_printf et tout équivalent
|
||||
que VOUS avez codé
|
||||
|
||||
Libft autorisée Oui
|
||||
Description Ce projet consiste à créer un petit logiciel
|
||||
d’exploration fractale. Commencez donc par voir
|
||||
ce qu’est une fractale.
|
||||
|
||||
Votre projet doit respecter les règles suivantes :
|
||||
|
||||
• Vous devez utiliser la MiniLibX. Soit la version disponible sur les machines de
|
||||
l’école, soit en l’installant par les sources.
|
||||
|
||||
• Vous devez rendre un Makefile qui compilera vos fichiers sources. Il ne doit pas
|
||||
relink.
|
||||
|
||||
• Les variables globales sont interdites.
|
||||
|
||||
6
|
||||
fract’ol Art fractal
|
||||
|
||||
V.1 Rendu
|
||||
|
||||
• Votre programme doit proposer les ensembles de Julia et Mandelbrot.
|
||||
|
||||
• La molette de la souris doit permettre de zoomer et dézoomer, et cela de façon
|
||||
quasi-infinie (dans les limites de la machine). C’est le principe même des fractales.
|
||||
|
||||
• En donnant des paramètres différents au programme, il doit être possible de créer
|
||||
différents ensembles de Julia.
|
||||
|
||||
• Au moins un paramètre est passé en ligne de commande pour définir quel type de
|
||||
fractale est à afficher dans la fenêtre.
|
||||
|
||||
◦ Il est possible de gérer des paramètres en plus afin de les utiliser pour le rendu.
|
||||
|
||||
◦ Si aucun paramètre n’est fourni ou si le paramètre est invalide, le programme
|
||||
doit afficher la liste des paramètres disponibles et quitter proprement.
|
||||
|
||||
• Il doit y avoir un jeu de couleur minimum pour ressentir la profondeur de chaque
|
||||
fractale. Mieux : lâchez-vous sur les effets psychédéliques.
|
||||
|
||||
V.2 Gestion graphique
|
||||
|
||||
• Votre programme doit afficher une image dans une fenêtre.
|
||||
|
||||
• La gestion de la fenêtre doit rester fluide (changer de fenêtre, la réduire, etc.).
|
||||
|
||||
• Appuyer sur la touche ESC doit fermer la fenêtre et quitter le programme propre-
|
||||
ment.
|
||||
|
||||
• Cliquer sur la croix en haut de la fenêtre doit fermer celle-ci et quitter le programme
|
||||
proprement.
|
||||
|
||||
• Utiliser les images de la MiniLibX est obligatoire.
|
||||
|
||||
7
|
||||
Chapitre VI
|
||||
Partie bonus
|
||||
|
||||
Habituellement, vous seriez encouragé(e) à développer vos propres bonus. Cependant,
|
||||
d’autres projets graphiques plus intéressants sont à venir. Ne perdez pas de temps !
|
||||
|
||||
Vous aurez des points supplémentaires si :
|
||||
• Il y a une fractale différente supplémentaire (il existe plus d’une centaine de types
|
||||
|
||||
différents de fractales référencés en ligne).
|
||||
• Le zoom suit la position de la souris.
|
||||
• En plus du zoom : on peut déplacer la vue avec les touches flèches.
|
||||
• Les couleurs changent (color shift).
|
||||
|
||||
Les bonus ne seront évalués que si la partie obligatoire est
|
||||
PARFAITE. Par parfaite, nous entendons complète et sans aucun
|
||||
dysfonctionnement. Si vous n’avez pas réussi TOUS les points de la
|
||||
partie obligatoire, votre partie bonus ne sera pas prise en compte.
|
||||
|
||||
8
|
||||
Chapitre VII
|
||||
Rendu et peer-evaluation
|
||||
|
||||
Rendez votre travail sur votre dépot Git comme d’habitude. Seul le travail présent
|
||||
sur votre dépot sera évalué en soutenance. Vérifiez bien les noms de vos dossiers et de
|
||||
vos fichiers afin que ces derniers soient conformes aux demandes du sujet.
|
||||
|
||||
Vu que votre travail ne sera pas évalué par un programme, organisez vos fichiers
|
||||
comme bon vous semble du moment que vous rendez les fichiers obligatoires et respectez
|
||||
les consignes du sujet.
|
||||
|
||||
file.bfe:VAD2sO2qgbqPEXROeASsmsgnY0o0sDMJev7zFHhw
|
||||
QS8mvM8V5xQQpLc6cDCFXDWTiFzZ2H9skYkiJ/DpQtnM/uZ0
|
||||
|
||||
9
|
||||
|
||||
63
fractol.c
Executable file
63
fractol.c
Executable file
@ -0,0 +1,63 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fractol.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:14:35 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:17:07 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
static void start_value(t_fractol *fractol, char **str)
|
||||
{
|
||||
fractol->name = ft_strjoin("Fractol: ", str[1]);
|
||||
fractol->color = 1;
|
||||
fractol->x_min = MIN_X;
|
||||
fractol->x_max = MAX_X;
|
||||
fractol->y_min = MIN_Y;
|
||||
fractol->y_max = MAX_Y;
|
||||
if (fractol->name[9] == 'j')
|
||||
{
|
||||
fractol->julia_x = atf(str[2]);
|
||||
fractol->julia_y = atf(str[3]);
|
||||
}
|
||||
}
|
||||
|
||||
void choose(t_fractol *fractol)
|
||||
{
|
||||
fractol->img = mlx_new_image(fractol->mlx, IMG_X, IMG_Y);
|
||||
fractol->img_addr = (char *)mlx_get_data_addr(fractol->img, \
|
||||
&fractol->img_bits_per_pixel, \
|
||||
&fractol->img_line_length, &fractol->img_endian);
|
||||
if (fractol->name[9] == 'm')
|
||||
mandelbrot(fractol);
|
||||
if (fractol->name[9] == 'j')
|
||||
julia(fractol);
|
||||
mlx_put_image_to_window(fractol->mlx, fractol->win, fractol->img, 0, 0);
|
||||
mlx_destroy_image(fractol->mlx, fractol->img);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
t_fractol *fractol;
|
||||
|
||||
if (check_arguments(argc, argv) == 1)
|
||||
{
|
||||
fractol = (t_fractol *)malloc(sizeof (t_fractol));
|
||||
start_value(fractol, argv);
|
||||
fractol->mlx = mlx_init();
|
||||
fractol->win = mlx_new_window(fractol->mlx, IMG_X, IMG_Y, \
|
||||
fractol->name);
|
||||
choose(fractol);
|
||||
mlx_hook(fractol->win, 17, 1L << 0, &close_program, fractol);
|
||||
mlx_key_hook(fractol->win, key_hook, fractol);
|
||||
mlx_mouse_hook(fractol->win, zoom, fractol);
|
||||
mlx_expose_hook(fractol->win, (void *)choose, fractol);
|
||||
mlx_loop(fractol-> mlx);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
71
fractol.h
Executable file
71
fractol.h
Executable file
@ -0,0 +1,71 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fractol.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 14:46:34 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:10:15 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FRACTOL_H
|
||||
# define FRACTOL_H
|
||||
|
||||
# define MAX_ITER 100
|
||||
# define MIN_X -2
|
||||
# define MAX_X 2
|
||||
# define MIN_Y -2
|
||||
# define MAX_Y 2
|
||||
# define IMG_X 1240
|
||||
# define IMG_Y 1240
|
||||
|
||||
# define DEF_COLOR "\033[0m"
|
||||
# define GRAY "\033[0;90m"
|
||||
# define RED "\033[0;91m"
|
||||
# define GREEN "\033[0;92m"
|
||||
# define YELLOW "\033[0;93m"
|
||||
# define BLUE "\033[0;94m"
|
||||
# define MAGENTA "\033[0;95m"
|
||||
# define CYAN "\033[0;96m"
|
||||
# define WHITE "\033[0;97m"
|
||||
# define ORANGE "\033[38;5;214m"
|
||||
|
||||
# include "minilibx-linux/mlx.h"
|
||||
# include "libft/libft.h"
|
||||
# include <math.h>
|
||||
|
||||
typedef struct s_fractol
|
||||
{
|
||||
void *mlx;
|
||||
void *win;
|
||||
void *img;
|
||||
char *img_addr;
|
||||
char *name;
|
||||
int color;
|
||||
int img_bits_per_pixel;
|
||||
int img_line_length;
|
||||
int img_endian;
|
||||
double x;
|
||||
double y;
|
||||
double x_min;
|
||||
double x_max;
|
||||
double y_min;
|
||||
double y_max;
|
||||
double julia_x;
|
||||
double julia_y;
|
||||
} t_fractol;
|
||||
|
||||
int zoom(int keycode, int x, int y, t_fractol *s_fractol);
|
||||
int key_hook(int keycode, t_fractol *fractol);
|
||||
int check_arguments(int argc, char **argv);
|
||||
int close_program(t_fractol *fractol);
|
||||
int color(int i, t_fractol *fractol);
|
||||
double atf( char *str);
|
||||
void my_img_pixel_put(t_fractol *fractol, int x, int y, int color);
|
||||
void mandelbrot(t_fractol *fractol);
|
||||
void julia(t_fractol *fractol);
|
||||
void choose(t_fractol *fractol);
|
||||
|
||||
#endif
|
||||
66
fractol_bonus.c
Executable file
66
fractol_bonus.c
Executable file
@ -0,0 +1,66 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fractol_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:17:36 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:18:49 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol_bonus.h"
|
||||
|
||||
static void start_value(t_fractol *fractol, char **str)
|
||||
{
|
||||
fractol->name = ft_strjoin("Fractol: ", str[1]);
|
||||
fractol->color = 1;
|
||||
fractol->x_min = MIN_X;
|
||||
fractol->x_max = MAX_X;
|
||||
fractol->y_min = MIN_Y;
|
||||
fractol->y_max = MAX_Y;
|
||||
if (fractol->name[9] == 'j')
|
||||
{
|
||||
fractol->julia_x = atf(str[2]);
|
||||
fractol->julia_y = atf(str[3]);
|
||||
}
|
||||
}
|
||||
|
||||
void choose(t_fractol *fractol)
|
||||
{
|
||||
fractol->img = mlx_new_image(fractol->mlx, IMG_X, IMG_Y);
|
||||
fractol->img_addr = (char *)mlx_get_data_addr(fractol->img, \
|
||||
&fractol->img_bits_per_pixel, \
|
||||
&fractol->img_line_length, &fractol->img_endian);
|
||||
if (fractol->name[9] == 'm')
|
||||
mandelbrot(fractol);
|
||||
if (fractol->name[9] == 'j')
|
||||
julia(fractol);
|
||||
if (fractol->name[9] == 'b')
|
||||
burning(fractol);
|
||||
mlx_put_image_to_window(fractol->mlx, fractol->win, fractol->img, 0, 0);
|
||||
mlx_destroy_image(fractol->mlx, fractol->img);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
t_fractol *fractol;
|
||||
|
||||
if (check_arguments(argc, argv) == 1)
|
||||
{
|
||||
fractol = (t_fractol *)malloc(sizeof (t_fractol));
|
||||
start_value(fractol, argv);
|
||||
fractol->mlx = mlx_init();
|
||||
fractol->win = mlx_new_window(fractol->mlx, IMG_X, IMG_Y, \
|
||||
fractol->name);
|
||||
choose(fractol);
|
||||
mlx_hook(fractol->win, 17, 1L << 0, &close_program, fractol);
|
||||
mlx_key_hook(fractol->win, key_hook, fractol);
|
||||
mlx_mouse_hook(fractol->win, zoom, fractol);
|
||||
mlx_mouse_hook(fractol->win, zoom_mouse, fractol);
|
||||
mlx_expose_hook(fractol->win, (void *)choose, fractol);
|
||||
mlx_loop(fractol-> mlx);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
74
fractol_bonus.h
Executable file
74
fractol_bonus.h
Executable file
@ -0,0 +1,74 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fractol_bonus.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:13:18 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:13:51 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FRACTOL_BONUS_H
|
||||
# define FRACTOL_BONUS_H
|
||||
|
||||
# define MAX_ITER 100
|
||||
# define MIN_X -2
|
||||
# define MAX_X 2
|
||||
# define MIN_Y -2
|
||||
# define MAX_Y 2
|
||||
# define IMG_Y 1920
|
||||
# define IMG_X 1920
|
||||
|
||||
# define DEF_COLOR "\033[0m"
|
||||
# define GRAY "\033[0;90m"
|
||||
# define RED "\033[0;91m"
|
||||
# define GREEN "\033[0;92m"
|
||||
# define YELLOW "\033[0;93m"
|
||||
# define BLUE "\033[0;94m"
|
||||
# define MAGENTA "\033[0;95m"
|
||||
# define CYAN "\033[0;96m"
|
||||
# define WHITE "\033[0;97m"
|
||||
# define ORANGE "\033[38;5;214m"
|
||||
|
||||
# include "minilibx-linux/mlx.h"
|
||||
# include "libft/libft.h"
|
||||
# include <math.h>
|
||||
|
||||
typedef struct s_fractol
|
||||
{
|
||||
void *mlx;
|
||||
void *win;
|
||||
void *img;
|
||||
char *img_addr;
|
||||
char *name;
|
||||
int color;
|
||||
int img_bits_per_pixel;
|
||||
int img_line_length;
|
||||
int img_endian;
|
||||
double x;
|
||||
double y;
|
||||
double x_min;
|
||||
double x_max;
|
||||
double y_min;
|
||||
double y_max;
|
||||
double julia_x;
|
||||
double julia_y;
|
||||
}t_fractol;
|
||||
|
||||
int zoom_mouse(int keycode, int x, int y, t_fractol *fractol);
|
||||
int zoom(int keycode, int x, int y, t_fractol *s_fractol);
|
||||
int key_hook(int keycode, t_fractol *fractol);
|
||||
int check_arguments(int argc, char **argv);
|
||||
int close_program(t_fractol *fractol);
|
||||
int color(int i, t_fractol *fractol);
|
||||
double atf( char *str);
|
||||
void my_img_pixel_put(t_fractol *fractol, int x, int y, int color);
|
||||
void mandelbrot(t_fractol *fractol);
|
||||
void julia(t_fractol *fractol);
|
||||
void burning(t_fractol *fractol);
|
||||
void choose(t_fractol *fractol);
|
||||
void change_color(int keycode, t_fractol *fractol);
|
||||
|
||||
#endif
|
||||
45
fractol_utils.c
Executable file
45
fractol_utils.c
Executable file
@ -0,0 +1,45 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fractol_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:23:25 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:25:14 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
void my_img_pixel_put(t_fractol *fractol, int x, int y, int color)
|
||||
{
|
||||
char *byte;
|
||||
|
||||
byte = fractol->img_addr + ((y * fractol->img_line_length) \
|
||||
+ (x * fractol->img_bits_per_pixel / 8));
|
||||
*(unsigned int *)byte = color;
|
||||
}
|
||||
|
||||
double atf(char *str)
|
||||
{
|
||||
double atf;
|
||||
int base;
|
||||
int i;
|
||||
|
||||
base = 1;
|
||||
i = 1;
|
||||
while (i < (int)ft_strlen(ft_strchr(str, '.')))
|
||||
{
|
||||
base *= 10;
|
||||
i ++;
|
||||
}
|
||||
atf = (float)ft_atoi(str);
|
||||
if (!ft_strchr(str, '.'))
|
||||
return (atf);
|
||||
if (str[0] != '-')
|
||||
atf += (float)ft_atoi(ft_strchr(str, '.') + 1) / base;
|
||||
else
|
||||
atf -= (float)ft_atoi(ft_strchr(str, '.') + 1) / base;
|
||||
return (atf);
|
||||
}
|
||||
45
fractol_utils_bonus.c
Executable file
45
fractol_utils_bonus.c
Executable file
@ -0,0 +1,45 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* fractol_utils_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:25:43 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:26:05 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol_bonus.h"
|
||||
|
||||
void my_img_pixel_put(t_fractol *fractol, int x, int y, int color)
|
||||
{
|
||||
char *byte;
|
||||
|
||||
byte = fractol->img_addr + ((y * fractol->img_line_length) \
|
||||
+ (x * fractol->img_bits_per_pixel / 8));
|
||||
*(unsigned int *)byte = color;
|
||||
}
|
||||
|
||||
double atf(char *str)
|
||||
{
|
||||
double atf;
|
||||
int base;
|
||||
int i;
|
||||
|
||||
base = 1;
|
||||
i = 1;
|
||||
while (i < (int)ft_strlen(ft_strchr(str, '.')))
|
||||
{
|
||||
base *= 10;
|
||||
i ++;
|
||||
}
|
||||
atf = (float)ft_atoi(str);
|
||||
if (!ft_strchr(str, '.'))
|
||||
return (atf);
|
||||
if (str[0] != '-')
|
||||
atf += (float)ft_atoi(ft_strchr(str, '.') + 1) / base;
|
||||
else
|
||||
atf -= (float)ft_atoi(ft_strchr(str, '.') + 1) / base;
|
||||
return (atf);
|
||||
}
|
||||
59
hook.c
Executable file
59
hook.c
Executable file
@ -0,0 +1,59 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* hook.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:26:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:28:23 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
int close_program(t_fractol *fractol)
|
||||
{
|
||||
mlx_destroy_window(fractol->mlx, fractol->win);
|
||||
mlx_destroy_display(fractol->mlx);
|
||||
free (fractol->mlx);
|
||||
free(fractol->name);
|
||||
free(fractol);
|
||||
exit(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int key_hook(int keycode, t_fractol *fractol)
|
||||
{
|
||||
if (keycode == 65307)
|
||||
close_program(fractol);
|
||||
choose(fractol);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int zoom(int keycode, int x, int y, t_fractol *fractol)
|
||||
{
|
||||
float dx;
|
||||
float dy;
|
||||
|
||||
dx = (fractol->x_max - fractol->x_min) / 3;
|
||||
dy = (fractol->y_max - fractol->y_min) / 3;
|
||||
if (keycode == 4)
|
||||
{
|
||||
fractol->x_min = (fractol->x_min + dx);
|
||||
fractol->x_max = (fractol->x_max - dx);
|
||||
fractol->y_min = (fractol->y_min + dy);
|
||||
fractol->y_max = (fractol->y_max - dy);
|
||||
}
|
||||
if (keycode == 5)
|
||||
{
|
||||
fractol->x_min = (fractol->x_min - dx);
|
||||
fractol->x_max = (fractol->x_max + dx);
|
||||
fractol->y_min = (fractol->y_min - dy);
|
||||
fractol->y_max = (fractol->y_max + dy);
|
||||
}
|
||||
dx = x;
|
||||
dy = y;
|
||||
choose(fractol);
|
||||
return (0);
|
||||
}
|
||||
109
hook_bonus.c
Executable file
109
hook_bonus.c
Executable file
@ -0,0 +1,109 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* hook_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:29:12 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:39:58 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol_bonus.h"
|
||||
|
||||
static void direction(int keycode, t_fractol *fractol)
|
||||
{
|
||||
float dx;
|
||||
float dy;
|
||||
|
||||
if (keycode == 65361 || keycode == 65363)
|
||||
{
|
||||
dx = (fractol->x_max - fractol->x_min);
|
||||
if (keycode == 65361)
|
||||
dx *= -1;
|
||||
fractol->x_min += dx / 3.0;
|
||||
fractol->x_max += dx / 3.0;
|
||||
}
|
||||
if (keycode == 65362 || keycode == 65364)
|
||||
{
|
||||
dy = (fractol->y_max - fractol->y_min);
|
||||
if (keycode == 65364)
|
||||
dy *= -1;
|
||||
fractol->y_min += dy / 3.0;
|
||||
fractol->y_max += dy / 3.0;
|
||||
}
|
||||
}
|
||||
|
||||
int close_program(t_fractol *fractol)
|
||||
{
|
||||
mlx_destroy_window(fractol->mlx, fractol->win);
|
||||
mlx_destroy_display(fractol->mlx);
|
||||
free (fractol->mlx);
|
||||
free(fractol->name);
|
||||
free(fractol);
|
||||
exit(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int key_hook(int keycode, t_fractol *fractol)
|
||||
{
|
||||
if (keycode == 65307)
|
||||
close_program(fractol);
|
||||
direction (keycode, fractol);
|
||||
change_color(keycode, fractol);
|
||||
choose(fractol);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int zoom(int keycode, int x, int y, t_fractol *fractol)
|
||||
{
|
||||
float dx;
|
||||
float dy;
|
||||
|
||||
dx = (fractol->x_max - fractol->x_min) / 3;
|
||||
dy = (fractol->y_max - fractol->y_min) / 3;
|
||||
if (keycode == 4)
|
||||
{
|
||||
fractol->x_min = (fractol->x_min + dx);
|
||||
fractol->x_max = (fractol->x_max - dx);
|
||||
fractol->y_min = (fractol->y_min + dy);
|
||||
fractol->y_max = (fractol->y_max - dy);
|
||||
}
|
||||
if (keycode == 5)
|
||||
{
|
||||
fractol->x_min = (fractol->x_min - dx);
|
||||
fractol->x_max = (fractol->x_max + dx);
|
||||
fractol->y_min = (fractol->y_min - dy);
|
||||
fractol->y_max = (fractol->y_max + dy);
|
||||
}
|
||||
dx = x;
|
||||
dy = y;
|
||||
choose(fractol);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int zoom_mouse(int keycode, int x, int y, t_fractol *fractol)
|
||||
{
|
||||
double mousex;
|
||||
double mousey;
|
||||
|
||||
mousex = fractol->x_min + (x * ((fractol->x_max - fractol->x_min) / IMG_X));
|
||||
mousey = fractol->y_max - (y * ((fractol->y_max - fractol->y_min) / IMG_Y));
|
||||
if (keycode == 4)
|
||||
{
|
||||
fractol->x_min = mousex - (mousex - fractol->x_min) * (2.0 / 3.0);
|
||||
fractol->x_max = mousex + (fractol->x_max - mousex) * (2.0 / 3.0);
|
||||
fractol->y_min = mousey - (mousey - fractol->y_min) * (2.0 / 3.0);
|
||||
fractol->y_max = mousey + (fractol->y_max - mousey) * (2.0 / 3.0);
|
||||
}
|
||||
else if (keycode == 5)
|
||||
{
|
||||
fractol->x_min = mousex - (mousex - fractol->x_min) * 1.5;
|
||||
fractol->x_max = mousex + (fractol->x_max - mousex) * 1.5;
|
||||
fractol->y_min = mousey - (mousey - fractol->y_min) * 1.5;
|
||||
fractol->y_max = mousey + (fractol->y_max - mousey) * 1.5;
|
||||
}
|
||||
choose(fractol);
|
||||
return (0);
|
||||
}
|
||||
59
julia.c
Executable file
59
julia.c
Executable file
@ -0,0 +1,59 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* julia.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:53:37 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:54:28 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
static int set_julia(t_fractol *fractol, double x, double y)
|
||||
{
|
||||
double xz;
|
||||
double yz;
|
||||
double temp;
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
xz = x;
|
||||
yz = y;
|
||||
while ((xz * xz + yz * yz <= 4) && (i < MAX_ITER))
|
||||
{
|
||||
i ++;
|
||||
temp = xz;
|
||||
xz = (xz * xz) - (yz * yz) + fractol->julia_x;
|
||||
yz = (2 * temp * yz) + fractol->julia_y;
|
||||
}
|
||||
if (i == MAX_ITER)
|
||||
return (0);
|
||||
return (i);
|
||||
}
|
||||
|
||||
void julia(t_fractol *fractol)
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
|
||||
fractol->x = 0;
|
||||
fractol->y = 0;
|
||||
while (fractol->y <= IMG_Y)
|
||||
{
|
||||
while (fractol->x <= IMG_X)
|
||||
{
|
||||
x = fractol->x_min + (fractol->x * ((fractol->x_max \
|
||||
- fractol->x_min) / IMG_X));
|
||||
y = fractol->y_max - (fractol->y * ((fractol->y_max \
|
||||
- fractol->y_min) / IMG_Y));
|
||||
my_img_pixel_put(fractol, fractol->x, fractol->y, \
|
||||
color(set_julia(fractol, x, y), fractol));
|
||||
fractol->x++;
|
||||
}
|
||||
fractol->x = 0;
|
||||
fractol->y ++;
|
||||
}
|
||||
}
|
||||
59
julia_bonus.c
Executable file
59
julia_bonus.c
Executable file
@ -0,0 +1,59 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* julia_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 16:43:30 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 16:43:49 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol_bonus.h"
|
||||
|
||||
static int set_julia(t_fractol *fractol, double x, double y)
|
||||
{
|
||||
double xz;
|
||||
double yz;
|
||||
double temp;
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
xz = x;
|
||||
yz = y;
|
||||
while ((xz * xz + yz * yz <= 4) && (i < MAX_ITER))
|
||||
{
|
||||
i ++;
|
||||
temp = xz;
|
||||
xz = (xz * xz) - (yz * yz) + fractol->julia_x;
|
||||
yz = (2 * temp * yz) + fractol->julia_y;
|
||||
}
|
||||
if (i == MAX_ITER)
|
||||
return (0);
|
||||
return (i);
|
||||
}
|
||||
|
||||
void julia(t_fractol *fractol)
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
|
||||
fractol->x = 0;
|
||||
fractol->y = 0;
|
||||
while (fractol->y <= IMG_Y)
|
||||
{
|
||||
while (fractol->x <= IMG_X)
|
||||
{
|
||||
x = fractol->x_min + (fractol->x * ((fractol->x_max \
|
||||
- fractol->x_min) / IMG_X));
|
||||
y = fractol->y_max - (fractol->y * ((fractol->y_max \
|
||||
- fractol->y_min) / IMG_Y));
|
||||
my_img_pixel_put(fractol, fractol->x, fractol->y, \
|
||||
color(set_julia(fractol, x, y), fractol));
|
||||
fractol->x++;
|
||||
}
|
||||
fractol->x = 0;
|
||||
fractol->y ++;
|
||||
}
|
||||
}
|
||||
91
libft/Makefile
Executable file
91
libft/Makefile
Executable file
@ -0,0 +1,91 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/02/06 12:19:21 by fgras-ca #+# #+# #
|
||||
# Updated: 2023/02/24 10:58:49 by fgras-ca ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = libft.a
|
||||
|
||||
SOURCES = ft_atoi.c \
|
||||
ft_isalpha.c \
|
||||
ft_memchr.c \
|
||||
ft_memset.c \
|
||||
ft_strlcat.c \
|
||||
ft_strnstr.c \
|
||||
ft_toupper.c \
|
||||
ft_bzero.c \
|
||||
ft_isascii.c \
|
||||
ft_memcmp.c \
|
||||
ft_strchr.c \
|
||||
ft_strlcpy.c \
|
||||
ft_strrchr.c \
|
||||
ft_calloc.c \
|
||||
ft_isdigit.c \
|
||||
ft_memcpy.c \
|
||||
ft_strdup.c \
|
||||
ft_strlen.c \
|
||||
ft_substr.c \
|
||||
ft_isalnum.c \
|
||||
ft_isprint.c \
|
||||
ft_memmove.c \
|
||||
ft_strjoin.c \
|
||||
ft_strncmp.c \
|
||||
ft_tolower.c\
|
||||
ft_strtrim.c \
|
||||
ft_putchar_fd.c \
|
||||
ft_putstr_fd.c \
|
||||
ft_putendl_fd.c \
|
||||
ft_putnbr_fd.c \
|
||||
ft_strmapi.c \
|
||||
ft_striteri.c \
|
||||
ft_split.c \
|
||||
ft_itoa.c \
|
||||
|
||||
SRCBONUS = ft_lstnew.c \
|
||||
ft_lstadd_front.c \
|
||||
ft_lstsize.c \
|
||||
ft_lstlast.c \
|
||||
ft_lstadd_back.c \
|
||||
ft_lstdelone.c \
|
||||
ft_lstclear.c \
|
||||
ft_lstiter.c \
|
||||
ft_lstiter.c \
|
||||
ft_lstmap.c \
|
||||
|
||||
OBJECTS = $(SOURCES:.c=.o)
|
||||
|
||||
BONUS_OBJ = $(SRCBONUS:.c=.o)
|
||||
|
||||
CC = gcc
|
||||
|
||||
RM = rm -f
|
||||
|
||||
CFLAGS = -Wall -Werror -Wextra
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJECTS)
|
||||
ar rcs $(NAME) $(OBJECTS)
|
||||
|
||||
bonus: $(OBJECTS) $(BONUS_OBJ)
|
||||
ar rcs $(NAME) $(OBJECTS) $(BONUS_OBJ)
|
||||
|
||||
main.o:
|
||||
gcc -c main.c
|
||||
|
||||
ccmainlib:
|
||||
$(CC) $(CFLAGS) main.c -L -lft
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJECTS) $(BONUS_OBJ)
|
||||
|
||||
fclean: clean
|
||||
$(RM) $(NAME)
|
||||
|
||||
re: fclean all
|
||||
38
libft/ft_atoi.c
Executable file
38
libft/ft_atoi.c
Executable file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/11 16:16:54 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 09:57:55 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_atoi(const char *nptr)
|
||||
{
|
||||
int i;
|
||||
int sign;
|
||||
int res;
|
||||
|
||||
i = 0;
|
||||
sign = 1;
|
||||
res = 0;
|
||||
while (nptr[i] == 32 || (nptr[i] >= 9 && nptr[i] <= 13))
|
||||
i++;
|
||||
if (nptr[i] == '-' || nptr[i] == '+')
|
||||
{
|
||||
if (nptr[i] == '-')
|
||||
sign = - (1);
|
||||
i++;
|
||||
}
|
||||
while (nptr[i] >= 48 && nptr[i] <= 57)
|
||||
{
|
||||
res = res * 10 + nptr[i] - 48;
|
||||
i++;
|
||||
}
|
||||
return (res * sign);
|
||||
}
|
||||
25
libft/ft_bzero.c
Executable file
25
libft/ft_bzero.c
Executable file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/04 11:37:30 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/20 16:07:19 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *ptr, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
*(char *)(ptr + i) = 0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
28
libft/ft_calloc.c
Executable file
28
libft/ft_calloc.c
Executable file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_calloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/11 17:47:38 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 10:45:58 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *ptr;
|
||||
|
||||
if (!nmemb || !size)
|
||||
return (malloc(0));
|
||||
if ((nmemb * size) / size != nmemb)
|
||||
return (NULL);
|
||||
ptr = malloc(size * nmemb);
|
||||
if (!ptr)
|
||||
return (0);
|
||||
ft_bzero(ptr, size * nmemb);
|
||||
return (ptr);
|
||||
}
|
||||
21
libft/ft_isalnum.c
Executable file
21
libft/ft_isalnum.c
Executable file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/01 16:21:11 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/01 16:24:23 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57))
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
21
libft/ft_isalpha.c
Executable file
21
libft/ft_isalpha.c
Executable file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/01 13:36:34 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/01 13:58:21 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122))
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
20
libft/ft_isascii.c
Executable file
20
libft/ft_isascii.c
Executable file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/01 16:40:31 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/01 16:46:11 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c >= 0 && c <= 127)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
21
libft/ft_isdigit.c
Executable file
21
libft/ft_isdigit.c
Executable file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/01 14:46:59 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/01 15:55:00 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
if (c >= 48 && c <= 57)
|
||||
return (1);
|
||||
else
|
||||
return (0);
|
||||
}
|
||||
20
libft/ft_isprint.c
Executable file
20
libft/ft_isprint.c
Executable file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/03 12:43:03 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/03 13:25:31 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
if (c >= 32 && c <= 126)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
56
libft/ft_itoa.c
Executable file
56
libft/ft_itoa.c
Executable file
@ -0,0 +1,56 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/17 15:53:35 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 10:21:07 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static size_t ft_len_nb(int nb)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
if (nb <= 0)
|
||||
len++;
|
||||
while (nb)
|
||||
{
|
||||
len++;
|
||||
nb = nb / 10;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
int len;
|
||||
char *str;
|
||||
long nb;
|
||||
|
||||
len = ft_len_nb(n);
|
||||
nb = n;
|
||||
str = malloc(sizeof(char) * len +1);
|
||||
if (!str)
|
||||
return (0);
|
||||
if (nb < 0)
|
||||
{
|
||||
str[0] = '-';
|
||||
nb = -nb;
|
||||
}
|
||||
if (nb == 0)
|
||||
str[0] = '0';
|
||||
str[len--] = '\0';
|
||||
while (nb)
|
||||
{
|
||||
str[len] = nb % 10 + '0';
|
||||
len--;
|
||||
nb = nb / 10;
|
||||
}
|
||||
return (str);
|
||||
}
|
||||
29
libft/ft_lstadd_back.c
Executable file
29
libft/ft_lstadd_back.c
Executable file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 18:08:00 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 18:15:14 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||
{
|
||||
t_list *temp;
|
||||
|
||||
if (new && lst)
|
||||
{
|
||||
if (*lst)
|
||||
{
|
||||
temp = ft_lstlast(*lst);
|
||||
temp->next = new;
|
||||
}
|
||||
else
|
||||
*lst = new;
|
||||
}
|
||||
}
|
||||
22
libft/ft_lstadd_front.c
Executable file
22
libft/ft_lstadd_front.c
Executable file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_front.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/22 18:06:54 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 17:13:45 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||
{
|
||||
if (new)
|
||||
{
|
||||
new->next = *lst;
|
||||
*lst = new;
|
||||
}
|
||||
}
|
||||
25
libft/ft_lstclear.c
Executable file
25
libft/ft_lstclear.c
Executable file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 18:19:42 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 18:22:17 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void*))
|
||||
{
|
||||
t_list *temp;
|
||||
|
||||
while (*lst && lst)
|
||||
{
|
||||
temp = (*lst)->next;
|
||||
ft_lstdelone(*lst, (*del));
|
||||
*lst = temp;
|
||||
}
|
||||
}
|
||||
21
libft/ft_lstdelone.c
Executable file
21
libft/ft_lstdelone.c
Executable file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 18:17:06 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 18:33:01 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void*))
|
||||
{
|
||||
if (!lst || !del)
|
||||
return ;
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
}
|
||||
24
libft/ft_lstiter.c
Executable file
24
libft/ft_lstiter.c
Executable file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 18:22:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 18:24:51 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
if (!lst || !f)
|
||||
return ;
|
||||
while (lst)
|
||||
{
|
||||
f(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
24
libft/ft_lstlast.c
Executable file
24
libft/ft_lstlast.c
Executable file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstlast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 17:48:29 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 18:02:44 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
while (lst)
|
||||
{
|
||||
if (lst->next == NULL)
|
||||
return (lst);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (lst);
|
||||
}
|
||||
35
libft/ft_lstmap.c
Executable file
35
libft/ft_lstmap.c
Executable file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 18:25:24 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 18:29:44 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *tmp;
|
||||
t_list *res;
|
||||
|
||||
if (!lst || !f)
|
||||
return (NULL);
|
||||
res = 0;
|
||||
while (lst)
|
||||
{
|
||||
tmp = ft_lstnew((*f)(lst->content));
|
||||
if (!tmp)
|
||||
{
|
||||
ft_lstclear(&res, del);
|
||||
return (NULL);
|
||||
}
|
||||
ft_lstadd_back(&res, tmp);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
25
libft/ft_lstnew.c
Executable file
25
libft/ft_lstnew.c
Executable file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/22 17:09:25 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 16:32:39 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *new;
|
||||
|
||||
new = malloc(sizeof(t_list));
|
||||
if (!new)
|
||||
return (0);
|
||||
new->content = content;
|
||||
new->next = 0;
|
||||
return (new);
|
||||
}
|
||||
28
libft/ft_lstsize.c
Executable file
28
libft/ft_lstsize.c
Executable file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstsize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/23 17:17:36 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/23 17:44:37 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int i;
|
||||
t_list *tmp;
|
||||
|
||||
tmp = lst;
|
||||
i = 0;
|
||||
while (tmp)
|
||||
{
|
||||
tmp = tmp->next;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
27
libft/ft_memchr.c
Executable file
27
libft/ft_memchr.c
Executable file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/10 13:42:10 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/14 13:03:28 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
if (((unsigned char *)s)[i] == (unsigned char)c)
|
||||
return ((void *)(s + i));
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
27
libft/ft_memcmp.c
Executable file
27
libft/ft_memcmp.c
Executable file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/10 14:45:56 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/14 13:05:03 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i])
|
||||
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
32
libft/ft_memcpy.c
Executable file
32
libft/ft_memcpy.c
Executable file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/04 14:43:15 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/20 16:13:43 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *destmov;
|
||||
char *srcmov;
|
||||
size_t i;
|
||||
|
||||
destmov = (char *)dest;
|
||||
srcmov = (char *)src;
|
||||
if (!dest && !src)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
destmov[i] = srcmov[i];
|
||||
i++;
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
42
libft/ft_memmove.c
Executable file
42
libft/ft_memmove.c
Executable file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/07 11:11:49 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/07 16:04:25 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *destmov;
|
||||
char *srcmov;
|
||||
size_t i;
|
||||
|
||||
if (!dest && !src)
|
||||
return (0);
|
||||
destmov = (char *)dest;
|
||||
srcmov = (char *)src;
|
||||
i = 0;
|
||||
if (destmov > srcmov)
|
||||
{
|
||||
while (n--)
|
||||
{
|
||||
destmov[n] = srcmov[n];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (n--)
|
||||
{
|
||||
destmov[i] = srcmov[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (destmov);
|
||||
}
|
||||
26
libft/ft_memset.c
Executable file
26
libft/ft_memset.c
Executable file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/03 15:49:51 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/20 16:05:34 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *s, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
*(unsigned char *)(s + i) = (unsigned char)c;
|
||||
i++;
|
||||
}
|
||||
return (s);
|
||||
}
|
||||
18
libft/ft_putchar_fd.c
Executable file
18
libft/ft_putchar_fd.c
Executable file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 11:23:07 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/15 11:30:37 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
28
libft/ft_putendl_fd.c
Executable file
28
libft/ft_putendl_fd.c
Executable file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 13:33:49 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 10:19:05 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char *s, int fd)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (!s)
|
||||
return ;
|
||||
while (s[i])
|
||||
{
|
||||
write(fd, &s[i], 1);
|
||||
i++;
|
||||
}
|
||||
write(fd, "\n", 1);
|
||||
}
|
||||
36
libft/ft_putnbr_fd.c
Executable file
36
libft/ft_putnbr_fd.c
Executable file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 13:53:25 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/15 14:00:06 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
if (n == -2147483648)
|
||||
{
|
||||
write(fd, "-2147483648", 11);
|
||||
}
|
||||
else if (n >= 0 && n < 10)
|
||||
{
|
||||
n += 48;
|
||||
ft_putchar_fd(n, fd);
|
||||
}
|
||||
else if (n < 0)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
ft_putnbr_fd((n * (-1)), fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_putnbr_fd(n / 10, fd);
|
||||
ft_putnbr_fd(n % 10, fd);
|
||||
}
|
||||
}
|
||||
27
libft/ft_putstr_fd.c
Executable file
27
libft/ft_putstr_fd.c
Executable file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/15 12:29:14 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/15 19:02:37 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char *s, int fd)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (!s || !fd)
|
||||
return ;
|
||||
while (s[i])
|
||||
{
|
||||
write(fd, &s[i], 1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
75
libft/ft_split.c
Executable file
75
libft/ft_split.c
Executable file
@ -0,0 +1,75 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_split.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/17 13:12:04 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 11:04:10 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int count_words(const char *s, char c)
|
||||
{
|
||||
int count;
|
||||
int trigger;
|
||||
|
||||
count = 0;
|
||||
trigger = 0;
|
||||
while (*s)
|
||||
{
|
||||
if (*s != c && trigger == 0)
|
||||
{
|
||||
trigger = 1;
|
||||
count++;
|
||||
}
|
||||
else if (*s == c)
|
||||
trigger = 0;
|
||||
s++;
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
|
||||
static char *word_cpy(const char *s, int start, int end)
|
||||
{
|
||||
char *word;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
word = malloc(sizeof(char) * (end - start + 1));
|
||||
while (start < end)
|
||||
word[i++] = s[start++];
|
||||
word[i] = '\0';
|
||||
return (word);
|
||||
}
|
||||
|
||||
char **ft_split(char const *s, char c)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
int index;
|
||||
char **split;
|
||||
|
||||
split = malloc(sizeof(char *) * (count_words(s, c) + 1));
|
||||
if (!s || !split)
|
||||
return (0);
|
||||
i = 0;
|
||||
j = 0;
|
||||
index = -1;
|
||||
while (i <= ft_strlen(s))
|
||||
{
|
||||
if (s[i] != c && index < 0)
|
||||
index = i;
|
||||
else if ((s[i] == c || i == ft_strlen(s)) && index >= 0)
|
||||
{
|
||||
split[j++] = word_cpy(s, index, i);
|
||||
index = -1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
split[j] = 0;
|
||||
return (split);
|
||||
}
|
||||
32
libft/ft_strchr.c
Executable file
32
libft/ft_strchr.c
Executable file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/09 14:27:10 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 10:54:39 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
|
||||
{
|
||||
int i;
|
||||
char *str;
|
||||
|
||||
str = (char *)s;
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
if (str[i] == (char)c)
|
||||
return (&str[i]);
|
||||
i++;
|
||||
}
|
||||
if (str[i] == (char)c)
|
||||
return (&str[i]);
|
||||
return (0);
|
||||
}
|
||||
31
libft/ft_strdup.c
Executable file
31
libft/ft_strdup.c
Executable file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/11 18:40:02 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/03/13 13:51:53 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
char *str;
|
||||
size_t i;
|
||||
|
||||
str = (char *)malloc(sizeof(char) * (ft_strlen(s) + 1));
|
||||
if (!str)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
str[i] = s[i];
|
||||
i++;
|
||||
}
|
||||
str[i] = 0;
|
||||
return (str);
|
||||
}
|
||||
25
libft/ft_striteri.c
Executable file
25
libft/ft_striteri.c
Executable file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/16 14:25:00 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/16 15:35:25 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if (!s)
|
||||
return ;
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
f(i, &s[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
39
libft/ft_strjoin.c
Executable file
39
libft/ft_strjoin.c
Executable file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/13 16:54:51 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/03/13 13:58:13 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
char *new_s;
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
if (!s1 || !s2)
|
||||
return (0);
|
||||
new_s = (char *)malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
|
||||
if (!new_s)
|
||||
return (0);
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (s1[i])
|
||||
{
|
||||
new_s[j] = s1[i];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
i = 0;
|
||||
while (s2[i])
|
||||
new_s[j++] = s2[i++];
|
||||
new_s[j] = '\0';
|
||||
return (new_s);
|
||||
}
|
||||
33
libft/ft_strlcat.c
Executable file
33
libft/ft_strlcat.c
Executable file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/08 14:10:58 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/20 16:19:44 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
size_t dst_len;
|
||||
|
||||
i = 0;
|
||||
if (!dst && !size)
|
||||
return (0);
|
||||
dst_len = ft_strlen(dst);
|
||||
if (size <= dst_len)
|
||||
return (size + ft_strlen(src));
|
||||
while (src[i] && i < size - dst_len -1)
|
||||
{
|
||||
dst[dst_len + i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dst[dst_len + i] = 0;
|
||||
return (dst_len + ft_strlen(src));
|
||||
}
|
||||
32
libft/ft_strlcpy.c
Executable file
32
libft/ft_strlcpy.c
Executable file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/08 13:24:31 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/08 13:33:32 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (size > 0)
|
||||
{
|
||||
while (src[i] && i < (size - 1))
|
||||
{
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dst[i] = 0;
|
||||
}
|
||||
while (src[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
23
libft/ft_strlen.c
Executable file
23
libft/ft_strlen.c
Executable file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/03 14:10:21 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/03 14:17:21 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (s[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
33
libft/ft_strmapi.c
Executable file
33
libft/ft_strmapi.c
Executable file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/16 13:38:52 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/16 13:51:01 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
char *result;
|
||||
unsigned int i;
|
||||
|
||||
if (!s)
|
||||
return (0);
|
||||
result = malloc(sizeof(char) * (ft_strlen(s) + 1));
|
||||
if (!result)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
result[i] = f(i, s[i]);
|
||||
i++;
|
||||
}
|
||||
result[i] = 0;
|
||||
return (result);
|
||||
}
|
||||
29
libft/ft_strncmp.c
Executable file
29
libft/ft_strncmp.c
Executable file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/09 17:12:38 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/14 13:26:15 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (n == 0)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
while (s1[i] == s2[i] && (s1[i] != '\0' || s2[i] != '\0') && i < (n - 1))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||
}
|
||||
41
libft/ft_strnstr.c
Executable file
41
libft/ft_strnstr.c
Executable file
@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/11 14:31:40 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/21 10:08:36 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *haystack, const char *needle, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
if (needle == haystack)
|
||||
return ((char *)haystack);
|
||||
if (!len && !haystack)
|
||||
return (0);
|
||||
while (haystack[i] != '\0')
|
||||
{
|
||||
j = 0;
|
||||
while (haystack[i + j] == needle[j] && (i + j) < len)
|
||||
{
|
||||
if (haystack[i + j] == '\0' && needle[j] == '\0')
|
||||
{
|
||||
return ((char *)&haystack[j]);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
if (needle[j] == '\0')
|
||||
return ((char *)(haystack + i));
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
29
libft/ft_strrchr.c
Executable file
29
libft/ft_strrchr.c
Executable file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/09 16:10:11 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/14 15:36:23 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s[i])
|
||||
i++;
|
||||
while (i >= 0)
|
||||
{
|
||||
if (s[i] == (char)c)
|
||||
return ((char *)(s + i));
|
||||
i--;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
52
libft/ft_strtrim.c
Executable file
52
libft/ft_strtrim.c
Executable file
@ -0,0 +1,52 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/14 16:30:26 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/03/13 14:12:41 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int char_in_set(char c, char const *set)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (set[i])
|
||||
{
|
||||
if (set[i] == c)
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *ft_strtrim(char const *s1, char const *set)
|
||||
{
|
||||
char *str;
|
||||
size_t i;
|
||||
size_t start;
|
||||
size_t end;
|
||||
|
||||
if (!s1)
|
||||
return (0);
|
||||
start = 0;
|
||||
while (s1[start] && char_in_set(s1[start], set))
|
||||
start++;
|
||||
end = ft_strlen(s1);
|
||||
while (end > start && char_in_set(s1[end - 1], set))
|
||||
end--;
|
||||
str = (char *)malloc(sizeof(*s1) * (end - start + 1));
|
||||
if (!str)
|
||||
return (0);
|
||||
i = 0;
|
||||
while (start < end)
|
||||
str[i++] = s1[start++];
|
||||
str[i] = 0;
|
||||
return (str);
|
||||
}
|
||||
37
libft/ft_substr.c
Executable file
37
libft/ft_substr.c
Executable file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_substr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/13 15:40:49 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/03/02 13:20:45 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
char *new_s;
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
new_s = (char *)malloc(sizeof(char) * (len + 1));
|
||||
if (!s || !new_s)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (s[i])
|
||||
{
|
||||
if (i >= start && j < len)
|
||||
{
|
||||
new_s[j] = s[i];
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
new_s[j] = '\0';
|
||||
return (new_s);
|
||||
}
|
||||
20
libft/ft_tolower.c
Executable file
20
libft/ft_tolower.c
Executable file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/09 14:09:59 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/14 13:36:02 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 65 && c <= 90)
|
||||
c += 32;
|
||||
return (c);
|
||||
}
|
||||
20
libft/ft_toupper.c
Executable file
20
libft/ft_toupper.c
Executable file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_toupper.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/08 16:02:00 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/14 13:36:40 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 97 && c <= 122)
|
||||
c -= 32;
|
||||
return (c);
|
||||
}
|
||||
71
libft/libft.h
Executable file
71
libft/libft.h
Executable file
@ -0,0 +1,71 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/12 10:46:53 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/02/24 11:20:17 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
# include <unistd.h>
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
int ft_isalpha(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_toupper(int c);
|
||||
int ft_tolower(int c);
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
int ft_atoi(const char *nptr);
|
||||
int ft_lstsize(t_list *lst);
|
||||
void *ft_memset(void *s, int c, size_t n);
|
||||
void ft_bzero(void *ptr, size_t len);
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putstr_fd(char *s, int fd);
|
||||
void ft_putendl_fd(char *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
||||
void ft_lstadd_front(t_list **lst, t_list *new);
|
||||
void ft_lstadd_back(t_list **lst, t_list *new);
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *));
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *));
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||
size_t ft_strlen(const char *s);
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
char *ft_strnstr(const char *haystack, const char *needle, size_t len);
|
||||
char *ft_strdup(const char *s);
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
char *ft_strmapi(const char *s, char (*f)(unsigned int, char));
|
||||
char **ft_split(char const *s, char c);
|
||||
char *ft_itoa(int n);
|
||||
t_list *ft_lstnew(void *content);
|
||||
t_list *ft_lstlast(t_list *lst);
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||
|
||||
#endif
|
||||
59
mandelbrot.c
Executable file
59
mandelbrot.c
Executable file
@ -0,0 +1,59 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mandelbrot.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 15:50:13 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 15:51:23 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol.h"
|
||||
|
||||
static int set_mandelbrot(double x, double y)
|
||||
{
|
||||
double xz;
|
||||
double yz;
|
||||
double temp;
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
xz = x;
|
||||
yz = y;
|
||||
while ((xz * xz + yz * yz <= 4) && (i < MAX_ITER))
|
||||
{
|
||||
i ++;
|
||||
temp = xz;
|
||||
xz = (xz * xz) - (yz * yz) + x;
|
||||
yz = (2 * temp * yz) + y;
|
||||
}
|
||||
if (i == MAX_ITER)
|
||||
return (0);
|
||||
return (i);
|
||||
}
|
||||
|
||||
void mandelbrot(t_fractol *fractol)
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
|
||||
fractol->x = 0;
|
||||
fractol->y = 0;
|
||||
while (fractol->y <= IMG_Y)
|
||||
{
|
||||
while (fractol->x <= IMG_X)
|
||||
{
|
||||
x = fractol->x_min + \
|
||||
(fractol->x * ((fractol->x_max - fractol->x_min) / IMG_X));
|
||||
y = fractol->y_max - \
|
||||
(fractol->y * ((fractol->y_max - fractol->y_min) / IMG_Y));
|
||||
my_img_pixel_put(fractol, fractol->x, fractol->y, \
|
||||
color(set_mandelbrot(x, y), fractol));
|
||||
fractol->x++;
|
||||
}
|
||||
fractol->x = 0;
|
||||
fractol->y ++;
|
||||
}
|
||||
}
|
||||
59
mandelbrot_bonus.c
Executable file
59
mandelbrot_bonus.c
Executable file
@ -0,0 +1,59 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mandelbrot_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/09/08 16:44:37 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/09/08 16:45:05 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fractol_bonus.h"
|
||||
|
||||
static int set_mandelbrot(double x, double y)
|
||||
{
|
||||
double xz;
|
||||
double yz;
|
||||
double temp;
|
||||
int i;
|
||||
|
||||
i = 1;
|
||||
xz = x;
|
||||
yz = y;
|
||||
while ((xz * xz + yz * yz <= 4) && (i < MAX_ITER))
|
||||
{
|
||||
i ++;
|
||||
temp = xz;
|
||||
xz = (xz * xz) - (yz * yz) + x;
|
||||
yz = (2 * temp * yz) + y;
|
||||
}
|
||||
if (i == MAX_ITER)
|
||||
return (0);
|
||||
return (i);
|
||||
}
|
||||
|
||||
void mandelbrot(t_fractol *fractol)
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
|
||||
fractol->x = 0;
|
||||
fractol->y = 0;
|
||||
while (fractol->y <= IMG_Y)
|
||||
{
|
||||
while (fractol->x <= IMG_X)
|
||||
{
|
||||
x = fractol->x_min + \
|
||||
(fractol->x * ((fractol->x_max - fractol->x_min) / IMG_X));
|
||||
y = fractol->y_max - \
|
||||
(fractol->y * ((fractol->y_max - fractol->y_min) / IMG_Y));
|
||||
my_img_pixel_put(fractol, fractol->x, fractol->y, \
|
||||
color(set_mandelbrot(x, y), fractol));
|
||||
fractol->x++;
|
||||
}
|
||||
fractol->x = 0;
|
||||
fractol->y ++;
|
||||
}
|
||||
}
|
||||
25
minilibx-linux/LICENSE
Executable file
25
minilibx-linux/LICENSE
Executable file
@ -0,0 +1,25 @@
|
||||
BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2021, Ecole 42
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
22
minilibx-linux/Makefile
Executable file
22
minilibx-linux/Makefile
Executable file
@ -0,0 +1,22 @@
|
||||
##
|
||||
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
||||
##
|
||||
## Made by Olivier Crouzet
|
||||
## Login <ol@epitech.net>
|
||||
##
|
||||
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
|
||||
## Last update Tue May 15 15:44:41 2007 Olivier Crouzet
|
||||
##
|
||||
|
||||
## Please use configure script
|
||||
|
||||
|
||||
all : do_configure
|
||||
|
||||
do_configure :
|
||||
./configure
|
||||
|
||||
clean :
|
||||
./configure clean
|
||||
|
||||
re : clean all
|
||||
66
minilibx-linux/Makefile.gen
Executable file
66
minilibx-linux/Makefile.gen
Executable file
@ -0,0 +1,66 @@
|
||||
INC=/usr/include
|
||||
##
|
||||
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
||||
##
|
||||
## Made by Olivier Crouzet
|
||||
## Login <ol@epitech.net>
|
||||
##
|
||||
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
|
||||
## Last update Tue May 15 15:41:20 2007 Olivier Crouzet
|
||||
##
|
||||
|
||||
## Please use configure script
|
||||
|
||||
|
||||
|
||||
UNAME = $(shell uname)
|
||||
CC = gcc
|
||||
ifeq ($(UNAME),FreeBSD)
|
||||
CC = clang
|
||||
endif
|
||||
|
||||
NAME = libmlx.a
|
||||
NAME_UNAME = libmlx_$(UNAME).a
|
||||
|
||||
SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
|
||||
mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \
|
||||
mlx_int_anti_resize_win.c mlx_int_do_nothing.c \
|
||||
mlx_int_wait_first_expose.c mlx_int_get_visual.c \
|
||||
mlx_flush_event.c mlx_string_put.c mlx_set_font.c \
|
||||
mlx_new_image.c mlx_get_data_addr.c \
|
||||
mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \
|
||||
mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \
|
||||
mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \
|
||||
mlx_rgb.c mlx_destroy_image.c mlx_mouse.c mlx_screen_size.c \
|
||||
mlx_destroy_display.c
|
||||
|
||||
OBJ_DIR = obj
|
||||
OBJ = $(addprefix $(OBJ_DIR)/,$(SRC:%.c=%.o))
|
||||
CFLAGS = -O3 -I$(INC)
|
||||
|
||||
all : $(NAME)
|
||||
|
||||
$(OBJ_DIR)/%.o: %.c
|
||||
@mkdir -p $(OBJ_DIR)
|
||||
$(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@
|
||||
|
||||
$(NAME) : $(OBJ)
|
||||
ar -r $(NAME) $(OBJ)
|
||||
ranlib $(NAME)
|
||||
cp $(NAME) $(NAME_UNAME)
|
||||
|
||||
check: all
|
||||
@test/run_tests.sh
|
||||
|
||||
show:
|
||||
@printf "NAME : $(NAME)\n"
|
||||
@printf "NAME_UNAME : $(NAME_UNAME)\n"
|
||||
@printf "CC : $(CC)\n"
|
||||
@printf "CFLAGS : $(CFLAGS)\n"
|
||||
@printf "SRC :\n $(SRC)\n"
|
||||
@printf "OBJ :\n $(OBJ)\n"
|
||||
|
||||
clean :
|
||||
rm -rf $(OBJ_DIR)/ $(NAME) $(NAME_UNAME) *~ core *.core
|
||||
|
||||
.PHONY: all check show clean
|
||||
66
minilibx-linux/Makefile.mk
Executable file
66
minilibx-linux/Makefile.mk
Executable file
@ -0,0 +1,66 @@
|
||||
##
|
||||
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
|
||||
##
|
||||
## Made by Olivier Crouzet
|
||||
## Login <ol@epitech.net>
|
||||
##
|
||||
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
|
||||
## Last update Tue May 15 15:41:20 2007 Olivier Crouzet
|
||||
##
|
||||
|
||||
## Please use configure script
|
||||
|
||||
|
||||
INC =%%%%
|
||||
|
||||
UNAME = $(shell uname)
|
||||
CC = gcc
|
||||
ifeq ($(UNAME),FreeBSD)
|
||||
CC = clang
|
||||
endif
|
||||
|
||||
NAME = libmlx.a
|
||||
NAME_UNAME = libmlx_$(UNAME).a
|
||||
|
||||
SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
|
||||
mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \
|
||||
mlx_int_anti_resize_win.c mlx_int_do_nothing.c \
|
||||
mlx_int_wait_first_expose.c mlx_int_get_visual.c \
|
||||
mlx_flush_event.c mlx_string_put.c mlx_set_font.c \
|
||||
mlx_new_image.c mlx_get_data_addr.c \
|
||||
mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \
|
||||
mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \
|
||||
mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \
|
||||
mlx_rgb.c mlx_destroy_image.c mlx_mouse.c mlx_screen_size.c \
|
||||
mlx_destroy_display.c
|
||||
|
||||
OBJ_DIR = obj
|
||||
OBJ = $(addprefix $(OBJ_DIR)/,$(SRC:%.c=%.o))
|
||||
CFLAGS = -O3 -I$(INC)
|
||||
|
||||
all : $(NAME)
|
||||
|
||||
$(OBJ_DIR)/%.o: %.c
|
||||
@mkdir -p $(OBJ_DIR)
|
||||
$(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@
|
||||
|
||||
$(NAME) : $(OBJ)
|
||||
ar -r $(NAME) $(OBJ)
|
||||
ranlib $(NAME)
|
||||
cp $(NAME) $(NAME_UNAME)
|
||||
|
||||
check: all
|
||||
@test/run_tests.sh
|
||||
|
||||
show:
|
||||
@printf "NAME : $(NAME)\n"
|
||||
@printf "NAME_UNAME : $(NAME_UNAME)\n"
|
||||
@printf "CC : $(CC)\n"
|
||||
@printf "CFLAGS : $(CFLAGS)\n"
|
||||
@printf "SRC :\n $(SRC)\n"
|
||||
@printf "OBJ :\n $(OBJ)\n"
|
||||
|
||||
clean :
|
||||
rm -rf $(OBJ_DIR)/ $(NAME) $(NAME_UNAME) *~ core *.core
|
||||
|
||||
.PHONY: all check show clean
|
||||
55
minilibx-linux/README.md
Executable file
55
minilibx-linux/README.md
Executable file
@ -0,0 +1,55 @@
|
||||
[](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml)
|
||||
|
||||
This is the MinilibX, a simple X-Window (X11R6) programming API
|
||||
in C, designed for students, suitable for X-beginners.
|
||||
|
||||
|
||||
Contents
|
||||
|
||||
- source code in C to create the mlx library
|
||||
- man pages (in man/ directory)
|
||||
- a test program (in test/ directory) is built
|
||||
with the library
|
||||
- a public include file mlx.h
|
||||
- a tiny configure script to generate an appropriate Makefile.gen
|
||||
|
||||
Requirements for Linux
|
||||
|
||||
- MinilibX only support TrueColor visual type (8,15,16,24 or 32 bits depth)
|
||||
- gcc
|
||||
- make
|
||||
- X11 include files (package xorg)
|
||||
- XShm extension must be present (package libxext-dev)
|
||||
- Utility functions from BSD systems - development files (package libbsd-dev)
|
||||
- **e.g. _sudo apt-get install gcc make xorg libxext-dev libbsd-dev_ (Debian/Ubuntu)**
|
||||
|
||||
Requirements for MacOS
|
||||
- [Xquartz](https://www.xquartz.org/)
|
||||
|
||||
```bash
|
||||
➜ ~ Brew install Xquartz
|
||||
➜ ~ reboot
|
||||
➜ ~ xeyes # run an hello world X11 app
|
||||
```
|
||||
|
||||
MlX Color Opacity / Transparency / Alpha (32 bits depth)
|
||||
- 0xFF (fully transparent) or 0x00 (fully opaque)
|
||||
|
||||
Compile MinilibX
|
||||
|
||||
- run ./configure or make
|
||||
both will make a few tests, create Makefile.gen
|
||||
and then automatically run make on this generated Makefile.gen .
|
||||
libmlx.a and libmlx_$(HOSTTYPE).a are created.
|
||||
test/mlx-test binary is also created.
|
||||
|
||||
|
||||
Install MinilibX
|
||||
|
||||
- no installation script is provided. You may want to install
|
||||
- libmlx.a and/or libmlx_$(HOSTTYPE).a in /usr/X11/lib or /usr/local/lib
|
||||
- mlx.h in /usr/X11/include or /usr/local/include
|
||||
- man/man3/mlx*.1 in /usr/X11/man/man3 or /usr/local/man/man3
|
||||
|
||||
|
||||
Olivier CROUZET - 2014-01-06 -
|
||||
126
minilibx-linux/configure
vendored
Executable file
126
minilibx-linux/configure
vendored
Executable file
@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -e
|
||||
|
||||
BOLD="\033[1m"
|
||||
RESET="\033[0m"
|
||||
LIGHT_RED="\033[91m"
|
||||
LIGHT_GREEN="\033[92m"
|
||||
LIGHT_CYAN="\033[96m"
|
||||
|
||||
logging(){
|
||||
local type=$1; shift
|
||||
printf "${LIGHT_CYAN}${BOLD}configure${RESET} [%b] : %b\n" "$type" "$*"
|
||||
}
|
||||
log_info(){
|
||||
logging "${LIGHT_GREEN}info${RESET}" "$@"
|
||||
}
|
||||
log_error(){
|
||||
logging "${LIGHT_RED}error${RESET}" "$@" >&2
|
||||
}
|
||||
|
||||
# find and print x11 header path
|
||||
get_xlib_include_path(){
|
||||
local result=""
|
||||
|
||||
for inc in \
|
||||
/usr/X11/include \
|
||||
/usr/X11R6/include \
|
||||
/usr/X11R5/include \
|
||||
/usr/X11R4/include \
|
||||
\
|
||||
/usr/include \
|
||||
/usr/include/X11 \
|
||||
/usr/include/X11R6 \
|
||||
/usr/include/X11R5 \
|
||||
/usr/include/X11R4 \
|
||||
\
|
||||
/usr/local/X11/include \
|
||||
/usr/local/X11R6/include \
|
||||
/usr/local/X11R5/include \
|
||||
/usr/local/X11R4/include \
|
||||
\
|
||||
/usr/local/include/X11 \
|
||||
/usr/local/include/X11R6 \
|
||||
/usr/local/include/X11R5 \
|
||||
/usr/local/include/X11R4 \
|
||||
\
|
||||
/usr/X386/include \
|
||||
/usr/x386/include \
|
||||
/usr/XFree86/include/X11 \
|
||||
\
|
||||
/usr/local/include \
|
||||
/usr/athena/include \
|
||||
/usr/local/x11r5/include \
|
||||
/usr/lpp/Xamples/include \
|
||||
\
|
||||
/usr/openwin/include \
|
||||
/usr/openwin/share/include
|
||||
do
|
||||
if [ -f "$inc/X11/Xlib.h" -a -f "$inc/X11/extensions/XShm.h" ]; then
|
||||
result=$inc
|
||||
break
|
||||
fi
|
||||
done
|
||||
echo $result
|
||||
}
|
||||
|
||||
show_help(){
|
||||
cat <<EOF
|
||||
Usage :
|
||||
$0 Auto-configure and make MinilibX
|
||||
$0 clean Execute the clean rule of both Makefile.gen
|
||||
EOF
|
||||
}
|
||||
|
||||
clean(){
|
||||
log_info 'Execute "make clean" from "makefile.gen"'
|
||||
${MAKE} -f Makefile.gen clean
|
||||
log_info 'Execute "make clean" from "test/makefile.gen"'
|
||||
${MAKE} -f Makefile.gen -C test/ --no-print-directory clean
|
||||
}
|
||||
|
||||
parse_args(){
|
||||
case "$1" in
|
||||
--help | -h)
|
||||
show_help
|
||||
exit 0;;
|
||||
clean)
|
||||
clean
|
||||
exit 0;;
|
||||
"") return;;
|
||||
*)
|
||||
log_error "unknown command \"$1\"\nRun \"./configure --help\" for usage."
|
||||
exit 1;;
|
||||
esac
|
||||
}
|
||||
|
||||
main(){
|
||||
local xlib_inc="$(get_xlib_include_path)"
|
||||
|
||||
case $(uname) in
|
||||
FreeBSD) MAKE=gmake ;;
|
||||
*) MAKE=make ;;
|
||||
esac
|
||||
|
||||
parse_args "$@"
|
||||
if [ -z "$xlib_inc" ]; then
|
||||
log_error "Can't find a suitable X11 include directory."
|
||||
exit 1
|
||||
fi
|
||||
log_info "Found X11 include path directory: $xlib_inc"
|
||||
|
||||
log_info 'Generate "makefile.gen" from template "makefile.mk"'
|
||||
echo "INC=$xlib_inc" > Makefile.gen
|
||||
cat Makefile.mk | grep -v %%%% >> Makefile.gen
|
||||
log_info 'Generate "test/makefile.gen" from template "test/makefile.mk"'
|
||||
echo "INC=$xlib_inc" > test/Makefile.gen
|
||||
cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen
|
||||
|
||||
log_info 'Execute "make all" from file "makefile.gen"'
|
||||
${MAKE} -f Makefile.gen all
|
||||
log_info 'Execute "make all" from file "test/makefile.gen"'
|
||||
(cd test ; ${MAKE} -f Makefile.gen all )
|
||||
}
|
||||
|
||||
main "$@"
|
||||
93
minilibx-linux/man/man1/mlx.1
Executable file
93
minilibx-linux/man/man1/mlx.1
Executable file
@ -0,0 +1,93 @@
|
||||
.TH MiniLibX 3 "September 19, 2002"
|
||||
.SH NAME
|
||||
MiniLibX - Simple X-Window Interface Library for students
|
||||
.SH SYNOPSYS
|
||||
#include <mlx.h>
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_init
|
||||
();
|
||||
|
||||
.SH DESCRIPTION
|
||||
MiniLibX is an easy way to create graphical software,
|
||||
without any X-Window programming knowledge. It provides
|
||||
simple window creation, a drawing tool, image and basic events
|
||||
management.
|
||||
|
||||
.SH X-WINDOW CONCEPT
|
||||
|
||||
X-Window is a network-oriented graphical system for Unix.
|
||||
It is based on two main parts:
|
||||
.br
|
||||
On one side, your software wants to draw something on the screen and/or
|
||||
get keyboard & mouse entries.
|
||||
.br
|
||||
On the other side, the X-Server manages the screen, keyboard and mouse
|
||||
(It is often refered to as a "display").
|
||||
.br
|
||||
A network connection must be established between these two entities to send
|
||||
drawing orders (from the software to the X-Server), and keyboard/mouse
|
||||
events (from the X-Server to the software).
|
||||
|
||||
.SH INCLUDE FILE
|
||||
.B mlx.h
|
||||
should be included for a correct use of the MiniLibX API.
|
||||
It only contains function prototypes, no structure is needed.
|
||||
|
||||
.SH LIBRARY FUNCTIONS
|
||||
.P
|
||||
First of all, you need to initialize the connection
|
||||
between your software and the display.
|
||||
Once this connection is established, you'll be able to
|
||||
use other MiniLibX functions to send the X-Server messages,
|
||||
like "I want to draw a yellow pixel in this window" or "did the
|
||||
user hit a key?".
|
||||
.P
|
||||
The
|
||||
.B mlx_init
|
||||
function will create this connection. No parameters are needed, ant it will
|
||||
return a
|
||||
.I "void *"
|
||||
identifier, used for further calls to the library routines.
|
||||
.P
|
||||
All other MiniLibX functions are described in the following man pages:
|
||||
|
||||
.TP 20
|
||||
.B mlx_new_window
|
||||
: manage windows
|
||||
.TP 20
|
||||
.B mlx_pixel_put
|
||||
: draw inside window
|
||||
.TP 20
|
||||
.B mlx_new_image
|
||||
: manipulate images
|
||||
.TP 20
|
||||
.B mlx_loop
|
||||
: handle keyboard or mouse events
|
||||
|
||||
.SH LINKING MiniLibX
|
||||
To use MiniLibX functions, you'll need to link
|
||||
your software with several libraries, including the MiniLibX library itself.
|
||||
To do this, simply add the following arguments at linking time:
|
||||
|
||||
.B -lmlx -lXext -lX11
|
||||
|
||||
You may also need to specify the path to these libraries, using
|
||||
the
|
||||
.B -L
|
||||
flag.
|
||||
|
||||
|
||||
.SH RETURN VALUES
|
||||
If
|
||||
.B mlx_init()
|
||||
fails to set up the connection to the X server, it will return NULL, otherwise
|
||||
a non-null pointer is returned as a connection identifier.
|
||||
|
||||
.SH SEE ALSO
|
||||
mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
||||
|
||||
.SH AUTHOR
|
||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
||||
141
minilibx-linux/man/man1/mlx_loop.1
Executable file
141
minilibx-linux/man/man1/mlx_loop.1
Executable file
@ -0,0 +1,141 @@
|
||||
.TH MiniLibX 3 "September 19, 2002"
|
||||
.SH NAME
|
||||
MiniLibX - Handle events
|
||||
.SH SYNOPSYS
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_loop
|
||||
(
|
||||
.I void *mlx_ptr
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_key_hook
|
||||
(
|
||||
.I void *win_ptr, int (*funct_ptr)(), void *param
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_mouse_hook
|
||||
(
|
||||
.I void *win_ptr, int (*funct_ptr)(), void *param
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_expose_hook
|
||||
(
|
||||
.I void *win_ptr, int (*funct_ptr)(), void *param
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_loop_hook
|
||||
(
|
||||
.I void *mlx_ptr, int (*funct_ptr)(), void *param
|
||||
);
|
||||
|
||||
.SH X-WINDOW EVENTS
|
||||
|
||||
The X-Window system is bi-directionnal. On one hand, the program sends orders to
|
||||
the screen to display pixels, images, and so on. On the other hand,
|
||||
it can get information from the keyboard and mouse associated to
|
||||
the screen. To do so, the program receives "events" from the keyboard or the
|
||||
mouse.
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
To receive events, you must use
|
||||
.B mlx_loop
|
||||
(). This function never returns. It is an infinite loop that waits for
|
||||
an event, and then calls a user-defined function associated with this event.
|
||||
A single parameter is needed, the connection identifier
|
||||
.I mlx_ptr
|
||||
(see the
|
||||
.B mlx manual).
|
||||
|
||||
You can assign different functions to the three following events:
|
||||
.br
|
||||
- A key is pressed
|
||||
.br
|
||||
- The mouse button is pressed
|
||||
.br
|
||||
- A part of the window should be re-drawn
|
||||
(this is called an "expose" event, and it is your program's job to handle it).
|
||||
.br
|
||||
|
||||
Each window can define a different function for the same event.
|
||||
|
||||
The three functions
|
||||
.B mlx_key_hook
|
||||
(),
|
||||
.B mlx_mouse_hook
|
||||
() and
|
||||
.B mlx_expose_hook
|
||||
() work exactly the same way.
|
||||
.I funct_ptr
|
||||
is a pointer to the function you want to be called
|
||||
when an event occurs. This assignment is specific to the window defined by the
|
||||
.I win_ptr
|
||||
identifier. The
|
||||
.I param
|
||||
adress will be passed to the function everytime it is called, and should be
|
||||
used to store the parameters it might need.
|
||||
|
||||
The syntax for the
|
||||
.B mlx_loop_hook
|
||||
() function is identical to the previous ones, but the given function will be
|
||||
called when no event occurs.
|
||||
|
||||
When it catches an event, the MiniLibX calls the corresponding function
|
||||
with fixed parameters:
|
||||
.nf
|
||||
|
||||
expose_hook(void *param);
|
||||
key_hook(int keycode,void *param);
|
||||
mouse_hook(int button,int x,int y,void *param);
|
||||
loop_hook(void *param);
|
||||
|
||||
.fi
|
||||
These function names are arbitrary. They here are used to distinguish
|
||||
parameters according to the event. These functions are NOT part of the
|
||||
MiniLibX.
|
||||
|
||||
.I param
|
||||
is the address specified in the mlx_*_hook calls. This address is never
|
||||
used nor modified by the MiniLibX. On key and mouse events, additional
|
||||
information is passed:
|
||||
.I keycode
|
||||
tells you which key is pressed (look for the X11 include file "keysymdef.h"),
|
||||
(
|
||||
.I x
|
||||
,
|
||||
.I y
|
||||
) are the coordinates of the mouse click in the window, and
|
||||
.I button
|
||||
tells you which mouse button was pressed.
|
||||
|
||||
.SH GOING FURTHER WITH EVENTS
|
||||
The MiniLibX provides a much generic access to all X-Window events. The
|
||||
.I mlx.h
|
||||
include define
|
||||
.B mlx_hook()
|
||||
in the same manner mlx_*_hook functions work. The event and mask values
|
||||
will be taken from the X11 include file "X.h".
|
||||
|
||||
See source code of mlx_int_param_event.c to find out how the MiniLibX will
|
||||
call your own function for a specific event.
|
||||
|
||||
.SH SEE ALSO
|
||||
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3)
|
||||
|
||||
.SH AUTHOR
|
||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
||||
192
minilibx-linux/man/man1/mlx_new_image.1
Executable file
192
minilibx-linux/man/man1/mlx_new_image.1
Executable file
@ -0,0 +1,192 @@
|
||||
.TH MiniLibX 3 "September 19, 2002"
|
||||
.SH NAME
|
||||
MiniLibX - Manipulating images
|
||||
.SH SYNOPSYS
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_new_image
|
||||
(
|
||||
.I void *mlx_ptr, int width, int height
|
||||
);
|
||||
|
||||
.nf
|
||||
.I char *
|
||||
.fi
|
||||
.B mlx_get_data_addr
|
||||
(
|
||||
.I void *img_ptr, int *bits_per_pixel, int *size_line, int *endian
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_put_image_to_window
|
||||
(
|
||||
.I void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y
|
||||
);
|
||||
|
||||
.nf
|
||||
.I unsigned int
|
||||
.fi
|
||||
.B mlx_get_color_value
|
||||
(
|
||||
.I void *mlx_ptr, int color
|
||||
);
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_xpm_to_image
|
||||
(
|
||||
.I void *mlx_ptr, char **xpm_data, int *width, int *height
|
||||
);
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_xpm_file_to_image
|
||||
(
|
||||
.I void *mlx_ptr, char *filename, int *width, int *height
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_destroy_image
|
||||
(
|
||||
.I void *mlx_ptr, void *img_ptr
|
||||
);
|
||||
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
.B mlx_new_image
|
||||
() creates a new image in memory. It returns a
|
||||
.I void *
|
||||
identifier needed to manipulate this image later. It only needs
|
||||
the size of the image to be created, using the
|
||||
.I width
|
||||
and
|
||||
.I height
|
||||
parameters, and the
|
||||
.I mlx_ptr
|
||||
connection identifier (see the
|
||||
.B mlx
|
||||
manual).
|
||||
|
||||
The user can draw inside the image (see below), and
|
||||
can dump the image inside a specified window at any time to
|
||||
display it on the screen. This is done using
|
||||
.B mlx_put_image_to_window
|
||||
(). Three identifiers are needed here, for the connection to the
|
||||
display, the window to use, and the image (respectively
|
||||
.I mlx_ptr
|
||||
,
|
||||
.I win_ptr
|
||||
and
|
||||
.I img_ptr
|
||||
). The (
|
||||
.I x
|
||||
,
|
||||
.I y
|
||||
) coordinates define where the image should be placed in the window.
|
||||
|
||||
.B mlx_get_data_addr
|
||||
() returns information about the created image, allowing a user
|
||||
to modify it later. The
|
||||
.I img_ptr
|
||||
parameter specifies the image to use. The three next parameters should
|
||||
be the addresses of three different valid integers.
|
||||
.I bits_per_pixel
|
||||
will be filled with the number of bits needed to represent a pixel color
|
||||
(also called the depth of the image).
|
||||
.I size_line
|
||||
is the number of bytes used to store one line of the image in memory.
|
||||
This information is needed to move from one line to another in the image.
|
||||
.I endian
|
||||
tells you wether the pixel color in the image needs to be stored in
|
||||
little endian (
|
||||
.I endian
|
||||
== 0), or big endian (
|
||||
.I endian
|
||||
== 1).
|
||||
|
||||
.B mlx_get_data_addr
|
||||
returns a
|
||||
.I char *
|
||||
address that represents the begining of the memory area where the image
|
||||
is stored. From this adress, the first
|
||||
.I bits_per_pixel
|
||||
bits represent the color of the first pixel in the first line of
|
||||
the image. The second group of
|
||||
.I bits_per_pixel
|
||||
bits represent the second pixel of the first line, and so on.
|
||||
Add
|
||||
.I size_line
|
||||
to the adress to get the begining of the second line. You can reach any
|
||||
pixels of the image that way.
|
||||
|
||||
.B mlx_destroy_image
|
||||
destroys the given image (
|
||||
.I img_ptr
|
||||
).
|
||||
|
||||
.SH STORING COLOR INSIDE IMAGES
|
||||
|
||||
Depending on the display, the number of bits used to store a pixel color
|
||||
can change. The user usually represents a color in RGB mode, using
|
||||
one byte for each component (see
|
||||
.B mlx_pixel_put
|
||||
manual). This must be translated to fit the
|
||||
.I bits_per_pixel
|
||||
requirement of the image, and make the color understandable to the X-Server.
|
||||
That is the purpose of the
|
||||
.B mlx_get_color_value
|
||||
() function. It takes a standard RGB
|
||||
.I color
|
||||
parameter, and returns an
|
||||
.I unsigned int
|
||||
value.
|
||||
The
|
||||
.I bits_per_pixel
|
||||
least significant bits of this value can be stored in the image.
|
||||
|
||||
Keep in mind that the least significant bits position depends on the local
|
||||
computer's endian. If the endian of the image (in fact the endian of
|
||||
the X-Server's computer) differs from the local endian, then the value should
|
||||
be transformed before being used.
|
||||
|
||||
.SH XPM IMAGES
|
||||
|
||||
The
|
||||
.B mlx_xpm_to_image
|
||||
() and
|
||||
.B mlx_xpm_file_to_image
|
||||
() functions will create a new image the same way.
|
||||
They will fill it using the specified
|
||||
.I xpm_data
|
||||
or
|
||||
.I filename
|
||||
, depending on which function is used.
|
||||
Note that MiniLibX does not use the standard
|
||||
Xpm library to deal with xpm images. You may not be able to
|
||||
read all types of xpm images. It however handles transparency.
|
||||
|
||||
.SH RETURN VALUES
|
||||
The three functions that create images,
|
||||
.B mlx_new_image()
|
||||
,
|
||||
.B mlx_xpm_to_image()
|
||||
and
|
||||
.B mlx_xpm_file_to_image()
|
||||
, will return NULL if an error occurs. Otherwise they return a non-null pointer
|
||||
as an image identifier.
|
||||
|
||||
|
||||
.SH SEE ALSO
|
||||
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3)
|
||||
|
||||
.SH AUTHOR
|
||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
||||
79
minilibx-linux/man/man1/mlx_new_window.1
Executable file
79
minilibx-linux/man/man1/mlx_new_window.1
Executable file
@ -0,0 +1,79 @@
|
||||
.TH MiniLibX 3 "September 19, 2002"
|
||||
.SH NAME
|
||||
MiniLibX - Managing windows
|
||||
.SH SYNOPSYS
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_new_window
|
||||
(
|
||||
.I void *mlx_ptr, int size_x, int size_y, char *title
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_clear_window
|
||||
(
|
||||
.I void *mlx_ptr, void *win_ptr
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_destroy_window
|
||||
(
|
||||
.I void *mlx_ptr, void *win_ptr
|
||||
);
|
||||
|
||||
|
||||
.SH DESCRIPTION
|
||||
The
|
||||
.B mlx_new_window
|
||||
() function creates a new window on the screen, using the
|
||||
.I size_x
|
||||
and
|
||||
.I size_y
|
||||
parameters to determine its size, and
|
||||
.I title
|
||||
as the text that should be displayed in the window's title bar.
|
||||
The
|
||||
.I mlx_ptr
|
||||
parameter is the connection identifier returned by
|
||||
.B mlx_init
|
||||
() (see the
|
||||
.B mlx
|
||||
man page).
|
||||
.B mlx_new_window
|
||||
() returns a
|
||||
.I void *
|
||||
window identifier that can be used by other MiniLibX calls.
|
||||
Note that the MiniLibX
|
||||
can handle an arbitrary number of separate windows.
|
||||
|
||||
.B mlx_clear_window
|
||||
() and
|
||||
.B mlx_destroy_window
|
||||
() respectively clear (in black) and destroy the given window. They both have
|
||||
the same parameters:
|
||||
.I mlx_ptr
|
||||
is the screen connection identifier, and
|
||||
.I win_ptr
|
||||
is a window identifier.
|
||||
|
||||
.SH RETURN VALUES
|
||||
If
|
||||
.B mlx_new_window()
|
||||
fails to create a new window (for wathever reason), it will return NULL,
|
||||
otherwise a non-null pointer is returned as a window identifier.
|
||||
.B mlx_clear_window
|
||||
and
|
||||
.B mlx_destroy_window
|
||||
right now return nothing.
|
||||
|
||||
.SH SEE ALSO
|
||||
mlx(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
||||
|
||||
.SH AUTHOR
|
||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
||||
93
minilibx-linux/man/man3/mlx.3
Executable file
93
minilibx-linux/man/man3/mlx.3
Executable file
@ -0,0 +1,93 @@
|
||||
.TH MiniLibX 3 "September 19, 2002"
|
||||
.SH NAME
|
||||
MiniLibX - Simple X-Window Interface Library for students
|
||||
.SH SYNOPSYS
|
||||
#include <mlx.h>
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_init
|
||||
();
|
||||
|
||||
.SH DESCRIPTION
|
||||
MiniLibX is an easy way to create graphical software,
|
||||
without any X-Window programming knowledge. It provides
|
||||
simple window creation, a drawing tool, image and basic events
|
||||
management.
|
||||
|
||||
.SH X-WINDOW CONCEPT
|
||||
|
||||
X-Window is a network-oriented graphical system for Unix.
|
||||
It is based on two main parts:
|
||||
.br
|
||||
On one side, your software wants to draw something on the screen and/or
|
||||
get keyboard & mouse entries.
|
||||
.br
|
||||
On the other side, the X-Server manages the screen, keyboard and mouse
|
||||
(It is often refered to as a "display").
|
||||
.br
|
||||
A network connection must be established between these two entities to send
|
||||
drawing orders (from the software to the X-Server), and keyboard/mouse
|
||||
events (from the X-Server to the software).
|
||||
|
||||
.SH INCLUDE FILE
|
||||
.B mlx.h
|
||||
should be included for a correct use of the MiniLibX API.
|
||||
It only contains function prototypes, no structure is needed.
|
||||
|
||||
.SH LIBRARY FUNCTIONS
|
||||
.P
|
||||
First of all, you need to initialize the connection
|
||||
between your software and the display.
|
||||
Once this connection is established, you'll be able to
|
||||
use other MiniLibX functions to send the X-Server messages,
|
||||
like "I want to draw a yellow pixel in this window" or "did the
|
||||
user hit a key?".
|
||||
.P
|
||||
The
|
||||
.B mlx_init
|
||||
function will create this connection. No parameters are needed, ant it will
|
||||
return a
|
||||
.I "void *"
|
||||
identifier, used for further calls to the library routines.
|
||||
.P
|
||||
All other MiniLibX functions are described in the following man pages:
|
||||
|
||||
.TP 20
|
||||
.B mlx_new_window
|
||||
: manage windows
|
||||
.TP 20
|
||||
.B mlx_pixel_put
|
||||
: draw inside window
|
||||
.TP 20
|
||||
.B mlx_new_image
|
||||
: manipulate images
|
||||
.TP 20
|
||||
.B mlx_loop
|
||||
: handle keyboard or mouse events
|
||||
|
||||
.SH LINKING MiniLibX
|
||||
To use MiniLibX functions, you'll need to link
|
||||
your software with several libraries, including the MiniLibX library itself.
|
||||
To do this, simply add the following arguments at linking time:
|
||||
|
||||
.B -lmlx -lXext -lX11
|
||||
|
||||
You may also need to specify the path to these libraries, using
|
||||
the
|
||||
.B -L
|
||||
flag.
|
||||
|
||||
|
||||
.SH RETURN VALUES
|
||||
If
|
||||
.B mlx_init()
|
||||
fails to set up the connection to the X server, it will return NULL, otherwise
|
||||
a non-null pointer is returned as a connection identifier.
|
||||
|
||||
.SH SEE ALSO
|
||||
mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3), mlx_loop(3)
|
||||
|
||||
.SH AUTHOR
|
||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
||||
141
minilibx-linux/man/man3/mlx_loop.3
Executable file
141
minilibx-linux/man/man3/mlx_loop.3
Executable file
@ -0,0 +1,141 @@
|
||||
.TH MiniLibX 3 "September 19, 2002"
|
||||
.SH NAME
|
||||
MiniLibX - Handle events
|
||||
.SH SYNOPSYS
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_loop
|
||||
(
|
||||
.I void *mlx_ptr
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_key_hook
|
||||
(
|
||||
.I void *win_ptr, int (*funct_ptr)(), void *param
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_mouse_hook
|
||||
(
|
||||
.I void *win_ptr, int (*funct_ptr)(), void *param
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_expose_hook
|
||||
(
|
||||
.I void *win_ptr, int (*funct_ptr)(), void *param
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_loop_hook
|
||||
(
|
||||
.I void *mlx_ptr, int (*funct_ptr)(), void *param
|
||||
);
|
||||
|
||||
.SH X-WINDOW EVENTS
|
||||
|
||||
The X-Window system is bi-directionnal. On one hand, the program sends orders to
|
||||
the screen to display pixels, images, and so on. On the other hand,
|
||||
it can get information from the keyboard and mouse associated to
|
||||
the screen. To do so, the program receives "events" from the keyboard or the
|
||||
mouse.
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
To receive events, you must use
|
||||
.B mlx_loop
|
||||
(). This function never returns. It is an infinite loop that waits for
|
||||
an event, and then calls a user-defined function associated with this event.
|
||||
A single parameter is needed, the connection identifier
|
||||
.I mlx_ptr
|
||||
(see the
|
||||
.B mlx manual).
|
||||
|
||||
You can assign different functions to the three following events:
|
||||
.br
|
||||
- A key is pressed
|
||||
.br
|
||||
- The mouse button is pressed
|
||||
.br
|
||||
- A part of the window should be re-drawn
|
||||
(this is called an "expose" event, and it is your program's job to handle it).
|
||||
.br
|
||||
|
||||
Each window can define a different function for the same event.
|
||||
|
||||
The three functions
|
||||
.B mlx_key_hook
|
||||
(),
|
||||
.B mlx_mouse_hook
|
||||
() and
|
||||
.B mlx_expose_hook
|
||||
() work exactly the same way.
|
||||
.I funct_ptr
|
||||
is a pointer to the function you want to be called
|
||||
when an event occurs. This assignment is specific to the window defined by the
|
||||
.I win_ptr
|
||||
identifier. The
|
||||
.I param
|
||||
adress will be passed to the function everytime it is called, and should be
|
||||
used to store the parameters it might need.
|
||||
|
||||
The syntax for the
|
||||
.B mlx_loop_hook
|
||||
() function is identical to the previous ones, but the given function will be
|
||||
called when no event occurs.
|
||||
|
||||
When it catches an event, the MiniLibX calls the corresponding function
|
||||
with fixed parameters:
|
||||
.nf
|
||||
|
||||
expose_hook(void *param);
|
||||
key_hook(int keycode,void *param);
|
||||
mouse_hook(int button,int x,int y,void *param);
|
||||
loop_hook(void *param);
|
||||
|
||||
.fi
|
||||
These function names are arbitrary. They here are used to distinguish
|
||||
parameters according to the event. These functions are NOT part of the
|
||||
MiniLibX.
|
||||
|
||||
.I param
|
||||
is the address specified in the mlx_*_hook calls. This address is never
|
||||
used nor modified by the MiniLibX. On key and mouse events, additional
|
||||
information is passed:
|
||||
.I keycode
|
||||
tells you which key is pressed (look for the X11 include file "keysymdef.h"),
|
||||
(
|
||||
.I x
|
||||
,
|
||||
.I y
|
||||
) are the coordinates of the mouse click in the window, and
|
||||
.I button
|
||||
tells you which mouse button was pressed.
|
||||
|
||||
.SH GOING FURTHER WITH EVENTS
|
||||
The MiniLibX provides a much generic access to all X-Window events. The
|
||||
.I mlx.h
|
||||
include define
|
||||
.B mlx_hook()
|
||||
in the same manner mlx_*_hook functions work. The event and mask values
|
||||
will be taken from the X11 include file "X.h".
|
||||
|
||||
See source code of mlx_int_param_event.c to find out how the MiniLibX will
|
||||
call your own function for a specific event.
|
||||
|
||||
.SH SEE ALSO
|
||||
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3)
|
||||
|
||||
.SH AUTHOR
|
||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
||||
192
minilibx-linux/man/man3/mlx_new_image.3
Executable file
192
minilibx-linux/man/man3/mlx_new_image.3
Executable file
@ -0,0 +1,192 @@
|
||||
.TH MiniLibX 3 "September 19, 2002"
|
||||
.SH NAME
|
||||
MiniLibX - Manipulating images
|
||||
.SH SYNOPSYS
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_new_image
|
||||
(
|
||||
.I void *mlx_ptr, int width, int height
|
||||
);
|
||||
|
||||
.nf
|
||||
.I char *
|
||||
.fi
|
||||
.B mlx_get_data_addr
|
||||
(
|
||||
.I void *img_ptr, int *bits_per_pixel, int *size_line, int *endian
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_put_image_to_window
|
||||
(
|
||||
.I void *mlx_ptr, void *win_ptr, void *img_ptr, int x, int y
|
||||
);
|
||||
|
||||
.nf
|
||||
.I unsigned int
|
||||
.fi
|
||||
.B mlx_get_color_value
|
||||
(
|
||||
.I void *mlx_ptr, int color
|
||||
);
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_xpm_to_image
|
||||
(
|
||||
.I void *mlx_ptr, char **xpm_data, int *width, int *height
|
||||
);
|
||||
|
||||
.nf
|
||||
.I void *
|
||||
.fi
|
||||
.B mlx_xpm_file_to_image
|
||||
(
|
||||
.I void *mlx_ptr, char *filename, int *width, int *height
|
||||
);
|
||||
|
||||
.nf
|
||||
.I int
|
||||
.fi
|
||||
.B mlx_destroy_image
|
||||
(
|
||||
.I void *mlx_ptr, void *img_ptr
|
||||
);
|
||||
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
.B mlx_new_image
|
||||
() creates a new image in memory. It returns a
|
||||
.I void *
|
||||
identifier needed to manipulate this image later. It only needs
|
||||
the size of the image to be created, using the
|
||||
.I width
|
||||
and
|
||||
.I height
|
||||
parameters, and the
|
||||
.I mlx_ptr
|
||||
connection identifier (see the
|
||||
.B mlx
|
||||
manual).
|
||||
|
||||
The user can draw inside the image (see below), and
|
||||
can dump the image inside a specified window at any time to
|
||||
display it on the screen. This is done using
|
||||
.B mlx_put_image_to_window
|
||||
(). Three identifiers are needed here, for the connection to the
|
||||
display, the window to use, and the image (respectively
|
||||
.I mlx_ptr
|
||||
,
|
||||
.I win_ptr
|
||||
and
|
||||
.I img_ptr
|
||||
). The (
|
||||
.I x
|
||||
,
|
||||
.I y
|
||||
) coordinates define where the image should be placed in the window.
|
||||
|
||||
.B mlx_get_data_addr
|
||||
() returns information about the created image, allowing a user
|
||||
to modify it later. The
|
||||
.I img_ptr
|
||||
parameter specifies the image to use. The three next parameters should
|
||||
be the addresses of three different valid integers.
|
||||
.I bits_per_pixel
|
||||
will be filled with the number of bits needed to represent a pixel color
|
||||
(also called the depth of the image).
|
||||
.I size_line
|
||||
is the number of bytes used to store one line of the image in memory.
|
||||
This information is needed to move from one line to another in the image.
|
||||
.I endian
|
||||
tells you wether the pixel color in the image needs to be stored in
|
||||
little endian (
|
||||
.I endian
|
||||
== 0), or big endian (
|
||||
.I endian
|
||||
== 1).
|
||||
|
||||
.B mlx_get_data_addr
|
||||
returns a
|
||||
.I char *
|
||||
address that represents the begining of the memory area where the image
|
||||
is stored. From this adress, the first
|
||||
.I bits_per_pixel
|
||||
bits represent the color of the first pixel in the first line of
|
||||
the image. The second group of
|
||||
.I bits_per_pixel
|
||||
bits represent the second pixel of the first line, and so on.
|
||||
Add
|
||||
.I size_line
|
||||
to the adress to get the begining of the second line. You can reach any
|
||||
pixels of the image that way.
|
||||
|
||||
.B mlx_destroy_image
|
||||
destroys the given image (
|
||||
.I img_ptr
|
||||
).
|
||||
|
||||
.SH STORING COLOR INSIDE IMAGES
|
||||
|
||||
Depending on the display, the number of bits used to store a pixel color
|
||||
can change. The user usually represents a color in RGB mode, using
|
||||
one byte for each component (see
|
||||
.B mlx_pixel_put
|
||||
manual). This must be translated to fit the
|
||||
.I bits_per_pixel
|
||||
requirement of the image, and make the color understandable to the X-Server.
|
||||
That is the purpose of the
|
||||
.B mlx_get_color_value
|
||||
() function. It takes a standard RGB
|
||||
.I color
|
||||
parameter, and returns an
|
||||
.I unsigned int
|
||||
value.
|
||||
The
|
||||
.I bits_per_pixel
|
||||
least significant bits of this value can be stored in the image.
|
||||
|
||||
Keep in mind that the least significant bits position depends on the local
|
||||
computer's endian. If the endian of the image (in fact the endian of
|
||||
the X-Server's computer) differs from the local endian, then the value should
|
||||
be transformed before being used.
|
||||
|
||||
.SH XPM IMAGES
|
||||
|
||||
The
|
||||
.B mlx_xpm_to_image
|
||||
() and
|
||||
.B mlx_xpm_file_to_image
|
||||
() functions will create a new image the same way.
|
||||
They will fill it using the specified
|
||||
.I xpm_data
|
||||
or
|
||||
.I filename
|
||||
, depending on which function is used.
|
||||
Note that MiniLibX does not use the standard
|
||||
Xpm library to deal with xpm images. You may not be able to
|
||||
read all types of xpm images. It however handles transparency.
|
||||
|
||||
.SH RETURN VALUES
|
||||
The three functions that create images,
|
||||
.B mlx_new_image()
|
||||
,
|
||||
.B mlx_xpm_to_image()
|
||||
and
|
||||
.B mlx_xpm_file_to_image()
|
||||
, will return NULL if an error occurs. Otherwise they return a non-null pointer
|
||||
as an image identifier.
|
||||
|
||||
|
||||
.SH SEE ALSO
|
||||
mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_loop(3)
|
||||
|
||||
.SH AUTHOR
|
||||
Copyright ol@ - 2002-2014 - Olivier Crouzet
|
||||
139
minilibx-linux/mlx.h
Executable file
139
minilibx-linux/mlx.h
Executable file
@ -0,0 +1,139 @@
|
||||
/*
|
||||
** mlx.h for MinilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
|
||||
** Last update Tue May 15 16:23:28 2007 Olivier Crouzet
|
||||
*/
|
||||
|
||||
/*
|
||||
** MinilibX - Please report bugs
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** FR msg - FR msg - FR msg
|
||||
**
|
||||
** La MinilibX utilise 2 librairies supplementaires qu'il
|
||||
** est necessaire de rajouter a la compilation :
|
||||
** -lmlx -lXext -lX11
|
||||
**
|
||||
** La MinilibX permet le chargement des images de type Xpm.
|
||||
** Notez que cette implementation est incomplete.
|
||||
** Merci de communiquer tout probleme de chargement d'image
|
||||
** de ce type.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MLX_H
|
||||
|
||||
#define MLX_H
|
||||
|
||||
|
||||
void *mlx_init();
|
||||
/*
|
||||
** needed before everything else.
|
||||
** return (void *)0 if failed
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** Basic actions
|
||||
*/
|
||||
|
||||
void *mlx_new_window(void *mlx_ptr, int size_x, int size_y, char *title);
|
||||
/*
|
||||
** return void *0 if failed
|
||||
*/
|
||||
int mlx_clear_window(void *mlx_ptr, void *win_ptr);
|
||||
int mlx_pixel_put(void *mlx_ptr, void *win_ptr, int x, int y, int color);
|
||||
/*
|
||||
** origin for x & y is top left corner of the window
|
||||
** y down is positive
|
||||
** color is 0x00RRGGBB
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** Image stuff
|
||||
*/
|
||||
|
||||
void *mlx_new_image(void *mlx_ptr,int width,int height);
|
||||
/*
|
||||
** return void *0 if failed
|
||||
** obsolete : image2 data is stored using bit planes
|
||||
** void *mlx_new_image2(void *mlx_ptr,int width,int height);
|
||||
*/
|
||||
char *mlx_get_data_addr(void *img_ptr, int *bits_per_pixel,
|
||||
int *size_line, int *endian);
|
||||
/*
|
||||
** endian : 0 = sever X is little endian, 1 = big endian
|
||||
** for mlx_new_image2, 2nd arg of mlx_get_data_addr is number_of_planes
|
||||
*/
|
||||
int mlx_put_image_to_window(void *mlx_ptr, void *win_ptr, void *img_ptr,
|
||||
int x, int y);
|
||||
int mlx_get_color_value(void *mlx_ptr, int color);
|
||||
|
||||
|
||||
/*
|
||||
** dealing with Events
|
||||
*/
|
||||
|
||||
int mlx_mouse_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
||||
int mlx_key_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
||||
int mlx_expose_hook (void *win_ptr, int (*funct_ptr)(), void *param);
|
||||
|
||||
int mlx_loop_hook (void *mlx_ptr, int (*funct_ptr)(), void *param);
|
||||
int mlx_loop (void *mlx_ptr);
|
||||
int mlx_loop_end (void *mlx_ptr);
|
||||
|
||||
/*
|
||||
** hook funct are called as follow :
|
||||
**
|
||||
** expose_hook(void *param);
|
||||
** key_hook(int keycode, void *param);
|
||||
** mouse_hook(int button, int x,int y, void *param);
|
||||
** loop_hook(void *param);
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
** Usually asked...
|
||||
*/
|
||||
|
||||
int mlx_string_put(void *mlx_ptr, void *win_ptr, int x, int y, int color,
|
||||
char *string);
|
||||
void mlx_set_font(void *mlx_ptr, void *win_ptr, char *name);
|
||||
void *mlx_xpm_to_image(void *mlx_ptr, char **xpm_data,
|
||||
int *width, int *height);
|
||||
void *mlx_xpm_file_to_image(void *mlx_ptr, char *filename,
|
||||
int *width, int *height);
|
||||
int mlx_destroy_window(void *mlx_ptr, void *win_ptr);
|
||||
|
||||
int mlx_destroy_image(void *mlx_ptr, void *img_ptr);
|
||||
|
||||
int mlx_destroy_display(void *mlx_ptr);
|
||||
|
||||
/*
|
||||
** generic hook system for all events, and minilibX functions that
|
||||
** can be hooked. Some macro and defines from X11/X.h are needed here.
|
||||
*/
|
||||
|
||||
int mlx_hook(void *win_ptr, int x_event, int x_mask,
|
||||
int (*funct)(), void *param);
|
||||
|
||||
int mlx_do_key_autorepeatoff(void *mlx_ptr);
|
||||
int mlx_do_key_autorepeaton(void *mlx_ptr);
|
||||
int mlx_do_sync(void *mlx_ptr);
|
||||
|
||||
int mlx_mouse_get_pos(void *mlx_ptr, void *win_ptr, int *x, int *y);
|
||||
int mlx_mouse_move(void *mlx_ptr, void *win_ptr, int x, int y);
|
||||
int mlx_mouse_hide(void *mlx_ptr, void *win_ptr);
|
||||
int mlx_mouse_show(void *mlx_ptr, void *win_ptr);
|
||||
|
||||
int mlx_get_screen_size(void *mlx_ptr, int *sizex, int *sizey);
|
||||
|
||||
#endif /* MLX_H */
|
||||
21
minilibx-linux/mlx_clear_window.c
Executable file
21
minilibx-linux/mlx_clear_window.c
Executable file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
** mlx_clear_window.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Thu Sep 7 19:46:15 2000 Charlie Root
|
||||
** Last update Tue Sep 25 17:11:19 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
int mlx_clear_window(t_xvar *xvar,t_win_list *win)
|
||||
{
|
||||
XClearWindow(xvar->display,win->window);
|
||||
if (xvar->do_flush)
|
||||
XFlush(xvar->display);
|
||||
}
|
||||
18
minilibx-linux/mlx_destroy_display.c
Executable file
18
minilibx-linux/mlx_destroy_display.c
Executable file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mlx_destroy_display.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mg <mg@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/10/03 18:56:35 by mg #+# #+# */
|
||||
/* Updated: 2020/10/04 01:55:35 by mg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
int mlx_destroy_display(t_xvar *xvar)
|
||||
{
|
||||
XCloseDisplay(xvar->display);
|
||||
}
|
||||
31
minilibx-linux/mlx_destroy_image.c
Executable file
31
minilibx-linux/mlx_destroy_image.c
Executable file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
** mlx_destroy_image.c for MinilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Tue Mar 12 10:25:15 2002 Charlie Root
|
||||
** Last update Tue May 15 16:45:54 2007 Olivier Crouzet
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
int mlx_destroy_image(t_xvar *xvar, t_img *img)
|
||||
{
|
||||
if (img->type == MLX_TYPE_SHM_PIXMAP ||
|
||||
img->type == MLX_TYPE_SHM)
|
||||
{
|
||||
XShmDetach(xvar->display, &(img->shm));
|
||||
shmdt(img->shm.shmaddr);
|
||||
/* shmctl IPC_RMID already done */
|
||||
}
|
||||
XDestroyImage(img->image); /* For image & shm-image. Also free img->data */
|
||||
XFreePixmap(xvar->display, img->pix);
|
||||
if (img->gc)
|
||||
XFreeGC(xvar->display, img->gc);
|
||||
free(img);
|
||||
if (xvar->do_flush)
|
||||
XFlush(xvar->display);
|
||||
}
|
||||
38
minilibx-linux/mlx_destroy_window.c
Executable file
38
minilibx-linux/mlx_destroy_window.c
Executable file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
** mlx_destroy_window.c for MinilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Tue Mar 12 10:25:15 2002 Charlie Root
|
||||
** Last update Tue May 15 16:46:08 2007 Olivier Crouzet
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
int mlx_destroy_window(t_xvar *xvar,t_win_list *win)
|
||||
{
|
||||
t_win_list *w;
|
||||
t_win_list *prev;
|
||||
t_win_list first;
|
||||
|
||||
first.next = xvar->win_list;
|
||||
prev = &first;
|
||||
w = prev->next;
|
||||
while (w)
|
||||
{
|
||||
if (w==win)
|
||||
prev->next = w->next;
|
||||
else
|
||||
prev = w;
|
||||
w = w->next;
|
||||
}
|
||||
xvar->win_list = first.next;
|
||||
XDestroyWindow(xvar->display,win->window);
|
||||
XFreeGC(xvar->display,win->gc);
|
||||
free(win);
|
||||
if (xvar->do_flush)
|
||||
XFlush(xvar->display);
|
||||
}
|
||||
22
minilibx-linux/mlx_expose_hook.c
Executable file
22
minilibx-linux/mlx_expose_hook.c
Executable file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
** mlx_expose_hook.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
||||
** Last update Fri Feb 23 17:07:42 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int mlx_expose_hook(t_win_list *win,int (*funct)(),void *param)
|
||||
{
|
||||
win->hooks[Expose].hook = funct;
|
||||
win->hooks[Expose].param = param;
|
||||
win->hooks[Expose].mask = ExposureMask;
|
||||
}
|
||||
104
minilibx-linux/mlx_ext_randr.c
Executable file
104
minilibx-linux/mlx_ext_randr.c
Executable file
@ -0,0 +1,104 @@
|
||||
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
|
||||
/* global for independant extension */
|
||||
|
||||
RRMode saved_mode = 0;
|
||||
|
||||
|
||||
int mlx_ext_fullscreen(t_xvar *xvar, t_win_list *win, int fullscreen)
|
||||
{
|
||||
XWindowAttributes watt;
|
||||
int i;
|
||||
int j;
|
||||
XRRScreenResources *res;
|
||||
XRROutputInfo *o_info;
|
||||
XRRCrtcInfo *crtc;
|
||||
RRMode mode_candidate;
|
||||
int idx_output;
|
||||
int idx_candidate;
|
||||
|
||||
if (!XGetWindowAttributes(xvar->display, win->window, &watt))
|
||||
return (0);
|
||||
|
||||
res = XRRGetScreenResources(xvar->display, xvar->root);
|
||||
o_info = NULL;
|
||||
idx_output = -1;
|
||||
i = res->noutput;
|
||||
while (i--)
|
||||
{
|
||||
o_info = XRRGetOutputInfo(xvar->display, res, res->outputs[i]);
|
||||
if (o_info->connection == RR_Connected)
|
||||
{
|
||||
idx_output = i;
|
||||
i = 0;
|
||||
}
|
||||
else
|
||||
XRRFreeOutputInfo(o_info);
|
||||
}
|
||||
if (!o_info)
|
||||
{
|
||||
XRRFreeScreenResources(res);
|
||||
return (0);
|
||||
}
|
||||
|
||||
idx_candidate = -1;
|
||||
i = o_info->nmode;
|
||||
while (i--)
|
||||
{
|
||||
j = res->nmode;
|
||||
while (j--)
|
||||
if (res->modes[j].id == o_info->modes[i])
|
||||
if (res->modes[j].width >= watt.width && res->modes[j].height >= watt.height &&
|
||||
(idx_candidate == -1 || res->modes[idx_candidate].width > res->modes[j].width ||
|
||||
res->modes[idx_candidate].height > res->modes[j].height) )
|
||||
idx_candidate = i;
|
||||
}
|
||||
if (idx_candidate < 0)
|
||||
{
|
||||
XRRFreeOutputInfo(o_info);
|
||||
XRRFreeScreenResources(res);
|
||||
return (0);
|
||||
}
|
||||
if (!fullscreen && saved_mode == -1)
|
||||
idx_candidate = 0; /* if no clue, uses first mode, usually part of npreferred */
|
||||
mode_candidate = o_info->modes[idx_candidate];
|
||||
if (!fullscreen)
|
||||
mode_candidate = saved_mode;
|
||||
|
||||
crtc = XRRGetCrtcInfo(xvar->display, res, o_info->crtc);
|
||||
saved_mode = crtc->mode;
|
||||
|
||||
i = XRRSetCrtcConfig(xvar->display, res, o_info->crtc, CurrentTime, 0, 0, mode_candidate,
|
||||
crtc->rotation, &res->outputs[idx_output], 1);
|
||||
if (fullscreen)
|
||||
printf("found mode : %d x %d\n Status %d\n", res->modes[idx_candidate].width, res->modes[idx_candidate].height, i);
|
||||
else
|
||||
printf("back previous mode\n");
|
||||
|
||||
XMoveWindow(xvar->display, win->window, 0, 0);
|
||||
XMapRaised(xvar->display, win->window);
|
||||
|
||||
if (fullscreen)
|
||||
{
|
||||
// XGrabPointer(xvar->display, win->window, True, 0, GrabModeAsync, GrabModeAsync, win->window, 0L, CurrentTime);
|
||||
XGrabKeyboard(xvar->display, win->window, False, GrabModeAsync, GrabModeAsync, CurrentTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
XUngrabPointer(xvar->display, CurrentTime);
|
||||
XUngrabKeyboard(xvar->display, CurrentTime);
|
||||
}
|
||||
|
||||
XSync(xvar->display, False);
|
||||
sleep(1);
|
||||
|
||||
XRRFreeCrtcInfo(crtc);
|
||||
XRRFreeOutputInfo(o_info);
|
||||
XRRFreeScreenResources(res);
|
||||
}
|
||||
25
minilibx-linux/mlx_flush_event.c
Executable file
25
minilibx-linux/mlx_flush_event.c
Executable file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
** mlx_flush_event.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Wed Aug 2 18:58:11 2000 Charlie Root
|
||||
** Last update Fri Feb 23 17:08:48 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int mlx_flush_event(t_xvar *xvar)
|
||||
{
|
||||
XEvent ev;
|
||||
|
||||
while (XPending(xvar->display))
|
||||
{
|
||||
XNextEvent(xvar->display,&ev);
|
||||
}
|
||||
}
|
||||
33
minilibx-linux/mlx_get_color_value.c
Executable file
33
minilibx-linux/mlx_get_color_value.c
Executable file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
** mlx_get_color_value.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Mon Jul 31 19:01:33 2000 Charlie Root
|
||||
** Last update Thu Oct 4 15:04:13 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
int mlx_get_color_value(t_xvar *xvar,int color)
|
||||
{
|
||||
return(mlx_int_get_good_color(xvar,color));
|
||||
}
|
||||
|
||||
int mlx_int_get_good_color(t_xvar *xvar,int color)
|
||||
{
|
||||
XColor xc;
|
||||
|
||||
if (xvar->depth>=24)
|
||||
return (color);
|
||||
xc.red = (color>>8)&0xFF00;
|
||||
xc.green = color&0xFF00;
|
||||
xc.blue = (color<<8)&0xFF00;
|
||||
xc.pixel = ((xc.red>>(16-xvar->decrgb[1]))<<xvar->decrgb[0])+
|
||||
((xc.green>>(16-xvar->decrgb[3]))<<xvar->decrgb[2])+
|
||||
((xc.blue>>(16-xvar->decrgb[5]))<<xvar->decrgb[4]);
|
||||
return (xc.pixel);
|
||||
}
|
||||
23
minilibx-linux/mlx_get_data_addr.c
Executable file
23
minilibx-linux/mlx_get_data_addr.c
Executable file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
** mlx_get_data_addr.c for MiniLibX in raytraceur
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Mon Aug 14 15:45:57 2000 Charlie Root
|
||||
** Last update Thu Sep 27 19:05:25 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
char *mlx_get_data_addr(t_img *img,int *bits_per_pixel,
|
||||
int *size_line,int *endian)
|
||||
{
|
||||
*bits_per_pixel = img->bpp;
|
||||
*size_line = img->size_line;
|
||||
*endian = img->image->byte_order;
|
||||
return (img->data);
|
||||
}
|
||||
40
minilibx-linux/mlx_hook.c
Executable file
40
minilibx-linux/mlx_hook.c
Executable file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
** mlx_hook.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
||||
** Last update Fri Jan 28 17:05:28 2005 Olivier Crouzet
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int mlx_hook(t_win_list *win, int x_event, int x_mask,
|
||||
int (*funct)(),void *param)
|
||||
{
|
||||
win->hooks[x_event].hook = funct;
|
||||
win->hooks[x_event].param = param;
|
||||
win->hooks[x_event].mask = x_mask;
|
||||
}
|
||||
|
||||
|
||||
int mlx_do_key_autorepeatoff(t_xvar *xvar)
|
||||
{
|
||||
XAutoRepeatOff(xvar->display);
|
||||
}
|
||||
|
||||
int mlx_do_key_autorepeaton(t_xvar *xvar)
|
||||
{
|
||||
XAutoRepeatOn(xvar->display);
|
||||
}
|
||||
|
||||
|
||||
int mlx_do_sync(t_xvar *xvar)
|
||||
{
|
||||
XSync(xvar->display, False);
|
||||
}
|
||||
99
minilibx-linux/mlx_init.c
Executable file
99
minilibx-linux/mlx_init.c
Executable file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
** mlx_init.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Mon Jul 31 16:52:42 2000 Charlie Root
|
||||
** Last update Fri Jan 28 17:05:09 2005 Olivier Crouzet
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
void *mlx_init()
|
||||
{
|
||||
t_xvar *xvar;
|
||||
|
||||
if (!(xvar = malloc(sizeof(*xvar))))
|
||||
return ((void*)0);
|
||||
if ((xvar->display = XOpenDisplay("")) == 0)
|
||||
{
|
||||
free(xvar);
|
||||
return ((void*)0);
|
||||
}
|
||||
xvar->screen = DefaultScreen(xvar->display);
|
||||
xvar->root = DefaultRootWindow(xvar->display);
|
||||
xvar->cmap = DefaultColormap(xvar->display,xvar->screen);
|
||||
xvar->depth = DefaultDepth(xvar->display,xvar->screen);
|
||||
if (mlx_int_get_visual(xvar)==-1)
|
||||
{
|
||||
printf(ERR_NO_TRUECOLOR);
|
||||
exit(1);
|
||||
}
|
||||
xvar->win_list = 0;
|
||||
xvar->loop_hook = 0;
|
||||
xvar->loop_param = (void *)0;
|
||||
xvar->do_flush = 1;
|
||||
xvar->wm_delete_window = XInternAtom (xvar->display, "WM_DELETE_WINDOW", False);
|
||||
xvar->wm_protocols = XInternAtom (xvar->display, "WM_PROTOCOLS", False);
|
||||
mlx_int_deal_shm(xvar);
|
||||
if (xvar->private_cmap)
|
||||
xvar->cmap = XCreateColormap(xvar->display,xvar->root,
|
||||
xvar->visual,AllocNone);
|
||||
mlx_int_rgb_conversion(xvar);
|
||||
xvar->end_loop = 0;
|
||||
return (xvar);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** pshm_format of -1 : Not XYBitmap|XYPixmap|ZPixmap
|
||||
** alpha libX need a check of the DISPLAY env var, or shm is allowed
|
||||
** in remote Xserver connections.
|
||||
*/
|
||||
|
||||
int mlx_int_deal_shm(t_xvar *xvar)
|
||||
{
|
||||
int use_pshm;
|
||||
int bidon;
|
||||
char *dpy;
|
||||
char buff[33];
|
||||
|
||||
xvar->use_xshm = XShmQueryVersion(xvar->display,&bidon,&bidon,&(use_pshm));
|
||||
if (xvar->use_xshm && use_pshm)
|
||||
xvar->pshm_format = XShmPixmapFormat(xvar->display);
|
||||
else
|
||||
xvar->pshm_format = -1;
|
||||
gethostname(buff,32);
|
||||
dpy = getenv(ENV_DISPLAY);
|
||||
if (dpy && strlen(dpy) && *dpy!=':' && strncmp(dpy,buff,strlen(buff)) &&
|
||||
strncmp(dpy,LOCALHOST,strlen(LOCALHOST)) )
|
||||
{
|
||||
xvar->pshm_format = -1;
|
||||
xvar->use_xshm = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** TrueColor Visual is needed to have *_mask correctly set
|
||||
*/
|
||||
|
||||
int mlx_int_rgb_conversion(t_xvar *xvar)
|
||||
{
|
||||
bzero(xvar->decrgb,sizeof(int)*6);
|
||||
while (!(xvar->visual->red_mask&1))
|
||||
{ xvar->visual->red_mask >>= 1; xvar->decrgb[0] ++; }
|
||||
while (xvar->visual->red_mask&1)
|
||||
{ xvar->visual->red_mask >>= 1; xvar->decrgb[1] ++; }
|
||||
while (!(xvar->visual->green_mask&1))
|
||||
{ xvar->visual->green_mask >>= 1; xvar->decrgb[2] ++; }
|
||||
while (xvar->visual->green_mask&1)
|
||||
{ xvar->visual->green_mask >>= 1; xvar->decrgb[3] ++; }
|
||||
while (!(xvar->visual->blue_mask&1))
|
||||
{ xvar->visual->blue_mask >>= 1; xvar->decrgb[4] ++; }
|
||||
while (xvar->visual->blue_mask&1)
|
||||
{ xvar->visual->blue_mask >>= 1; xvar->decrgb[5] ++; }
|
||||
}
|
||||
140
minilibx-linux/mlx_int.h
Executable file
140
minilibx-linux/mlx_int.h
Executable file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
** mlx_int.h for mlx in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Mon Jul 31 16:45:48 2000 Charlie Root
|
||||
** Last update Wed May 25 16:44:16 2011 Olivier Crouzet
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Internal settings for MiniLibX
|
||||
*/
|
||||
|
||||
#ifndef MLX_INT_H
|
||||
|
||||
# define MLX_INT_H
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/mman.h>
|
||||
# include <X11/Xlib.h>
|
||||
# include <X11/Xutil.h>
|
||||
# include <sys/ipc.h>
|
||||
# include <sys/shm.h>
|
||||
# include <X11/extensions/XShm.h>
|
||||
# include <X11/XKBlib.h>
|
||||
/* #include <X11/xpm.h> */
|
||||
|
||||
|
||||
# define MLX_TYPE_SHM_PIXMAP 3
|
||||
# define MLX_TYPE_SHM 2
|
||||
# define MLX_TYPE_XIMAGE 1
|
||||
|
||||
# define MLX_MAX_EVENT LASTEvent
|
||||
|
||||
|
||||
# define ENV_DISPLAY "DISPLAY"
|
||||
# define LOCALHOST "localhost"
|
||||
# define ERR_NO_TRUECOLOR "MinilibX Error : No TrueColor Visual available.\n"
|
||||
# define WARN_SHM_ATTACH "MinilibX Warning : X server can't attach shared memory.\n"
|
||||
|
||||
|
||||
typedef struct s_xpm_col
|
||||
{
|
||||
int name;
|
||||
int col;
|
||||
} t_xpm_col;
|
||||
|
||||
|
||||
struct s_col_name
|
||||
{
|
||||
char *name;
|
||||
int color;
|
||||
};
|
||||
|
||||
typedef struct s_event_list
|
||||
{
|
||||
int mask;
|
||||
int (*hook)();
|
||||
void *param;
|
||||
} t_event_list;
|
||||
|
||||
|
||||
typedef struct s_win_list
|
||||
{
|
||||
Window window;
|
||||
GC gc;
|
||||
struct s_win_list *next;
|
||||
int (*mouse_hook)();
|
||||
int (*key_hook)();
|
||||
int (*expose_hook)();
|
||||
void *mouse_param;
|
||||
void *key_param;
|
||||
void *expose_param;
|
||||
t_event_list hooks[MLX_MAX_EVENT];
|
||||
} t_win_list;
|
||||
|
||||
|
||||
typedef struct s_img
|
||||
{
|
||||
XImage *image;
|
||||
Pixmap pix;
|
||||
GC gc;
|
||||
int size_line;
|
||||
int bpp;
|
||||
int width;
|
||||
int height;
|
||||
int type;
|
||||
int format;
|
||||
char *data;
|
||||
XShmSegmentInfo shm;
|
||||
} t_img;
|
||||
|
||||
typedef struct s_xvar
|
||||
{
|
||||
Display *display;
|
||||
Window root;
|
||||
int screen;
|
||||
int depth;
|
||||
Visual *visual;
|
||||
Colormap cmap;
|
||||
int private_cmap;
|
||||
t_win_list *win_list;
|
||||
int (*loop_hook)();
|
||||
void *loop_param;
|
||||
int use_xshm;
|
||||
int pshm_format;
|
||||
int do_flush;
|
||||
int decrgb[6];
|
||||
Atom wm_delete_window;
|
||||
Atom wm_protocols;
|
||||
int end_loop;
|
||||
} t_xvar;
|
||||
|
||||
|
||||
int mlx_int_do_nothing();
|
||||
int mlx_get_color_value();
|
||||
int mlx_int_get_good_color();
|
||||
int mlx_int_find_in_pcm();
|
||||
int mlx_int_anti_resize_win();
|
||||
int mlx_int_wait_first_expose();
|
||||
int mlx_int_rgb_conversion();
|
||||
int mlx_int_deal_shm();
|
||||
void *mlx_int_new_xshm_image();
|
||||
char **mlx_int_str_to_wordtab();
|
||||
void *mlx_new_image();
|
||||
int shm_att_pb();
|
||||
int mlx_int_get_visual(t_xvar *xvar);
|
||||
int mlx_int_set_win_event_mask(t_xvar *xvar);
|
||||
int mlx_int_str_str_cote(char *str,char *find,int len);
|
||||
int mlx_int_str_str(char *str,char *find,int len);
|
||||
|
||||
|
||||
#endif
|
||||
28
minilibx-linux/mlx_int_anti_resize_win.c
Executable file
28
minilibx-linux/mlx_int_anti_resize_win.c
Executable file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
** mlx_int_anti_resize_win.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Tue Aug 8 14:31:05 2000 Charlie Root
|
||||
** Last update Tue Sep 25 15:56:58 2001 Charlie Root
|
||||
*/
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
int mlx_int_anti_resize_win(t_xvar *xvar,Window win,int w,int h)
|
||||
{
|
||||
XSizeHints hints;
|
||||
long toto;
|
||||
|
||||
XGetWMNormalHints(xvar->display,win,&hints,&toto);
|
||||
hints.width = w;
|
||||
hints.height = h;
|
||||
hints.min_width = w;
|
||||
hints.min_height = h;
|
||||
hints.max_width = w;
|
||||
hints.max_height = h;
|
||||
hints.flags = PPosition | PSize | PMinSize | PMaxSize;
|
||||
XSetWMNormalHints(xvar->display,win,&hints);
|
||||
}
|
||||
16
minilibx-linux/mlx_int_do_nothing.c
Executable file
16
minilibx-linux/mlx_int_do_nothing.c
Executable file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
** mlx_int_do_nothing.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Tue Aug 8 12:58:24 2000 Charlie Root
|
||||
** Last update Tue Sep 25 15:56:22 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int mlx_int_do_nothing(void *param)
|
||||
{
|
||||
|
||||
}
|
||||
39
minilibx-linux/mlx_int_get_visual.c
Executable file
39
minilibx-linux/mlx_int_get_visual.c
Executable file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
** mlx_int_get_visual.c for MinilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Wed Oct 3 17:01:51 2001 Charlie Root
|
||||
** Last update Thu Oct 4 15:00:45 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
/*
|
||||
** We need a private colormap for non-default Visual.
|
||||
*/
|
||||
|
||||
|
||||
int mlx_int_get_visual(t_xvar *xvar)
|
||||
{
|
||||
XVisualInfo *vi;
|
||||
XVisualInfo template;
|
||||
int nb_item;
|
||||
|
||||
xvar->private_cmap = 0;
|
||||
xvar->visual = DefaultVisual(xvar->display,xvar->screen);
|
||||
if (xvar->visual->class == TrueColor)
|
||||
return (0);
|
||||
template.class = TrueColor;
|
||||
template.depth = xvar->depth;
|
||||
if (!(vi = XGetVisualInfo(xvar->display,VisualDepthMask|VisualClassMask,
|
||||
&template,&nb_item)) )
|
||||
return (-1);
|
||||
xvar->visual = vi->visual;
|
||||
xvar->private_cmap = 1;
|
||||
return (0);
|
||||
}
|
||||
100
minilibx-linux/mlx_int_param_event.c
Executable file
100
minilibx-linux/mlx_int_param_event.c
Executable file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
** mlx_int_param_event.c for MinilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Mon Jul 31 16:37:50 2000 Charlie Root
|
||||
** Last update Wed Oct 6 13:14:52 2004 Olivier Crouzet
|
||||
*/
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
int mlx_int_param_undef()
|
||||
{
|
||||
}
|
||||
|
||||
int mlx_int_param_KeyPress(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
win->hooks[KeyPress].hook(XkbKeycodeToKeysym(xvar->display,
|
||||
ev->xkey.keycode, 0, 0),
|
||||
win->hooks[KeyPress].param);
|
||||
}
|
||||
|
||||
int mlx_int_param_KeyRelease(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
win->hooks[KeyRelease].hook(XkbKeycodeToKeysym(xvar->display,
|
||||
ev->xkey.keycode, 0, 0),
|
||||
win->hooks[KeyRelease].param);
|
||||
}
|
||||
|
||||
int mlx_int_param_ButtonPress(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
win->hooks[ButtonPress].hook(ev->xbutton.button,ev->xbutton.x,ev->xbutton.y,
|
||||
win->hooks[ButtonPress].param);
|
||||
}
|
||||
|
||||
int mlx_int_param_ButtonRelease(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
win->hooks[ButtonRelease].hook(ev->xbutton.button,
|
||||
ev->xbutton.x, ev->xbutton.y,
|
||||
win->hooks[ButtonRelease].param);
|
||||
}
|
||||
|
||||
int mlx_int_param_MotionNotify(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
win->hooks[MotionNotify].hook(ev->xbutton.x,ev->xbutton.y,
|
||||
win->hooks[MotionNotify].param);
|
||||
}
|
||||
|
||||
int mlx_int_param_Expose(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
if (!ev->xexpose.count)
|
||||
win->hooks[Expose].hook(win->hooks[Expose].param);
|
||||
}
|
||||
|
||||
|
||||
int mlx_int_param_generic(t_xvar *xvar, XEvent *ev, t_win_list *win)
|
||||
{
|
||||
win->hooks[ev->type].hook(win->hooks[ev->type].param);
|
||||
}
|
||||
|
||||
int (*(mlx_int_param_event[]))() =
|
||||
{
|
||||
mlx_int_param_undef, /* 0 */
|
||||
mlx_int_param_undef,
|
||||
mlx_int_param_KeyPress,
|
||||
mlx_int_param_KeyRelease, /* 3 */
|
||||
mlx_int_param_ButtonPress,
|
||||
mlx_int_param_ButtonRelease,
|
||||
mlx_int_param_MotionNotify, /* 6 */
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_Expose, /* 12 */
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic,
|
||||
mlx_int_param_generic
|
||||
};
|
||||
34
minilibx-linux/mlx_int_set_win_event_mask.c
Executable file
34
minilibx-linux/mlx_int_set_win_event_mask.c
Executable file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
** mlx_int_set_win_event_mask.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
||||
** Last update Fri Feb 23 17:07:42 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int mlx_int_set_win_event_mask(t_xvar *xvar)
|
||||
{
|
||||
t_win_list *win;
|
||||
int mask;
|
||||
int i;
|
||||
XSetWindowAttributes xwa;
|
||||
|
||||
win = xvar->win_list;
|
||||
while (win)
|
||||
{
|
||||
xwa.event_mask = 0;
|
||||
i = MLX_MAX_EVENT;
|
||||
while (i--)
|
||||
xwa.event_mask |= win->hooks[i].mask;
|
||||
XChangeWindowAttributes(xvar->display, win->window, CWEventMask, &xwa);
|
||||
win = win->next;
|
||||
}
|
||||
}
|
||||
113
minilibx-linux/mlx_int_str_to_wordtab.c
Executable file
113
minilibx-linux/mlx_int_str_to_wordtab.c
Executable file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
** mlx_int_str_to_wordtab.c for MinilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Wed Sep 13 11:36:09 2000 Charlie Root
|
||||
** Last update Fri Dec 14 11:02:09 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
int mlx_int_str_str(char *str,char *find,int len)
|
||||
{
|
||||
int len_f;
|
||||
int pos;
|
||||
char *s;
|
||||
char *f;
|
||||
|
||||
len_f = strlen(find);
|
||||
if (len_f>len)
|
||||
return (-1);
|
||||
pos = 0;
|
||||
while (*(str+len_f-1))
|
||||
{
|
||||
s = str;
|
||||
f = find;
|
||||
while (*(f++) == *(s++))
|
||||
if (!*f)
|
||||
return (pos);
|
||||
str ++;
|
||||
pos ++;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int mlx_int_str_str_cote(char *str,char *find,int len)
|
||||
{
|
||||
int len_f;
|
||||
int pos;
|
||||
char *s;
|
||||
char *f;
|
||||
int cote;
|
||||
|
||||
len_f = strlen(find);
|
||||
if (len_f>len)
|
||||
return (-1);
|
||||
cote = 0;
|
||||
pos = 0;
|
||||
while (*(str+len_f-1))
|
||||
{
|
||||
if (*str=='"')
|
||||
cote = 1-cote;
|
||||
if (!cote)
|
||||
{
|
||||
s = str;
|
||||
f = find;
|
||||
while (*(f++) == *(s++))
|
||||
if (!*f)
|
||||
return (pos);
|
||||
}
|
||||
str ++;
|
||||
pos ++;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
char **mlx_int_str_to_wordtab(char *str)
|
||||
{
|
||||
char **tab;
|
||||
int pos;
|
||||
int nb_word;
|
||||
int len;
|
||||
|
||||
len = strlen(str);
|
||||
nb_word = 0;
|
||||
pos = 0;
|
||||
while (pos<len)
|
||||
{
|
||||
while (*(str+pos)==' ' || *(str+pos)=='\t')
|
||||
pos ++;
|
||||
if (*(str+pos))
|
||||
nb_word ++;
|
||||
while (*(str+pos) && *(str+pos)!=' ' && *(str+pos)!='\t')
|
||||
pos ++;
|
||||
}
|
||||
if (!(tab = malloc((1+nb_word)*sizeof(*tab))))
|
||||
return ((char **)0);
|
||||
nb_word = 0;
|
||||
pos = 0;
|
||||
while (pos<len)
|
||||
{
|
||||
while (*(str+pos)==' ' || *(str+pos)=='\t')
|
||||
{
|
||||
*(str+pos) = 0;
|
||||
pos ++;
|
||||
}
|
||||
if (*(str+pos))
|
||||
{
|
||||
tab[nb_word] = str+pos;
|
||||
nb_word ++;
|
||||
}
|
||||
while (*(str+pos) && *(str+pos)!=' ' && *(str+pos)!='\t')
|
||||
pos ++;
|
||||
}
|
||||
tab[nb_word] = 0;
|
||||
return (tab);
|
||||
}
|
||||
23
minilibx-linux/mlx_int_wait_first_expose.c
Executable file
23
minilibx-linux/mlx_int_wait_first_expose.c
Executable file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
** mlx_int_wait_first_expose.c for minilibx in
|
||||
**
|
||||
** Made by olivier crouzet
|
||||
** Login <ol@epita.fr>
|
||||
**
|
||||
** Started on Tue Oct 17 09:26:45 2000 olivier crouzet
|
||||
** Last update Fri Feb 23 17:27:10 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
int mlx_int_wait_first_expose(t_xvar *xvar,Window win)
|
||||
{
|
||||
XEvent ev;
|
||||
|
||||
XWindowEvent(xvar->display,win,ExposureMask,&ev);
|
||||
XPutBackEvent(xvar->display,&ev);
|
||||
}
|
||||
22
minilibx-linux/mlx_key_hook.c
Executable file
22
minilibx-linux/mlx_key_hook.c
Executable file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
** mlx_key_hook.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Thu Aug 3 11:49:06 2000 Charlie Root
|
||||
** Last update Fri Feb 23 17:10:09 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int mlx_key_hook(t_win_list *win,int (*funct)(),void *param)
|
||||
{
|
||||
win->hooks[KeyRelease].hook = funct;
|
||||
win->hooks[KeyRelease].param = param;
|
||||
win->hooks[KeyRelease].mask = KeyReleaseMask;
|
||||
}
|
||||
96
minilibx-linux/mlx_lib_xpm.c
Executable file
96
minilibx-linux/mlx_lib_xpm.c
Executable file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
** mlx_xpm.c for minilibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Fri Dec 8 11:07:24 2000 Charlie Root
|
||||
** Last update Thu Oct 4 16:00:22 2001 Charlie Root
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
|
||||
|
||||
|
||||
void *mlx_int_xpm_f_image(t_xvar *xvar,int *width,int *height,
|
||||
int (*xpm_func)(),void *param)
|
||||
{
|
||||
XImage *img1;
|
||||
XImage *img2;
|
||||
t_img *im2;
|
||||
XpmAttributes xpm_att;
|
||||
|
||||
xpm_att.visual = xvar->visual;
|
||||
xpm_att.colormap = xvar->cmap;
|
||||
xpm_att.depth = xvar->depth;
|
||||
xpm_att.bitmap_format = ZPixmap;
|
||||
xpm_att.valuemask = XpmDepth|XpmBitmapFormat|XpmVisual|XpmColormap;
|
||||
if (xpm_func(xvar->display,param,&img1,&img2,&xpm_att))
|
||||
return ((void *)0);
|
||||
if (img2)
|
||||
XDestroyImage(img2);
|
||||
|
||||
if (!(im2 = (void *)mlx_new_image(xvar,img1->width,img1->height)))
|
||||
{
|
||||
XDestroyImage(img1);
|
||||
return ((void *)0);
|
||||
}
|
||||
*width = img1->width;
|
||||
*height = img1->height;
|
||||
if (mlx_int_egal_img(im2->image,img1))
|
||||
{
|
||||
bcopy(img1->data,im2->data,img1->height*img1->bytes_per_line);
|
||||
XDestroyImage(img1);
|
||||
return (im2);
|
||||
}
|
||||
if (im2->type==MLX_TYPE_SHM_PIXMAP)
|
||||
{
|
||||
XFreePixmap(xvar->display,im2->pix);
|
||||
im2->pix = XCreatePixmap(xvar->display,xvar->root,
|
||||
*width,*height,xvar->depth);
|
||||
}
|
||||
if (im2->type>MLX_TYPE_XIMAGE)
|
||||
{
|
||||
XShmDetach(xvar->display,&(im2->shm));
|
||||
shmdt(im2->data);
|
||||
}
|
||||
XDestroyImage(im2->image);
|
||||
im2->image = img1;
|
||||
im2->data = img1->data;
|
||||
im2->type = MLX_TYPE_XIMAGE;
|
||||
im2->size_line = img1->bytes_per_line;
|
||||
im2->bpp = img1->bits_per_pixel;
|
||||
return (im2);
|
||||
}
|
||||
|
||||
|
||||
int mlx_int_egal_img(XImage *img1,XImage *img2)
|
||||
{
|
||||
if (img1->width!=img2->width || img1->height!=img2->height ||
|
||||
img1->xoffset!=img2->xoffset || img1->format!=img2->format ||
|
||||
img1->byte_order!=img2->byte_order ||
|
||||
img1->bitmap_unit!=img2->bitmap_unit ||
|
||||
img1->bitmap_bit_order!=img2->bitmap_bit_order ||
|
||||
img1->bitmap_pad!=img2->bitmap_pad || img1->depth!=img2->depth ||
|
||||
img1->bytes_per_line!=img2->bytes_per_line ||
|
||||
img1->bits_per_pixel!=img2->bits_per_pixel ||
|
||||
img1->red_mask!=img2->red_mask || img1->green_mask!=img2->green_mask ||
|
||||
img1->blue_mask!=img2->blue_mask )
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
void *mlx_xpm_file_to_image(t_xvar *xvar,char *filename,
|
||||
int *width,int *height)
|
||||
{
|
||||
return (mlx_int_xpm_f_image(xvar,width,height,XpmReadFileToImage,filename));
|
||||
}
|
||||
|
||||
|
||||
void *mlx_xpm_to_image(t_xvar *xvar,char **data,int *width,int *height)
|
||||
{
|
||||
return (mlx_int_xpm_f_image(xvar,width,height,XpmCreateImageFromData,(void *)data));
|
||||
}
|
||||
63
minilibx-linux/mlx_loop.c
Executable file
63
minilibx-linux/mlx_loop.c
Executable file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
** mlx_loop.c for MiniLibX in
|
||||
**
|
||||
** Made by Charlie Root
|
||||
** Login <ol@epitech.net>
|
||||
**
|
||||
** Started on Wed Aug 2 18:58:11 2000 Charlie Root
|
||||
** Last update Fri Sep 30 14:47:41 2005 Olivier Crouzet
|
||||
*/
|
||||
|
||||
|
||||
#include "mlx_int.h"
|
||||
|
||||
extern int (*(mlx_int_param_event[]))();
|
||||
|
||||
static int win_count(t_xvar *xvar)
|
||||
{
|
||||
int i;
|
||||
t_win_list *win;
|
||||
|
||||
i = 0;
|
||||
win = xvar->win_list;
|
||||
while (win)
|
||||
{
|
||||
win = win->next;
|
||||
++i;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
int mlx_loop_end(t_xvar *xvar)
|
||||
{
|
||||
xvar->end_loop = 1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
int mlx_loop(t_xvar *xvar)
|
||||
{
|
||||
XEvent ev;
|
||||
t_win_list *win;
|
||||
|
||||
mlx_int_set_win_event_mask(xvar);
|
||||
xvar->do_flush = 0;
|
||||
while (win_count(xvar) && !xvar->end_loop)
|
||||
{
|
||||
while (!xvar->end_loop && (!xvar->loop_hook || XPending(xvar->display)))
|
||||
{
|
||||
XNextEvent(xvar->display,&ev);
|
||||
win = xvar->win_list;
|
||||
while (win && (win->window!=ev.xany.window))
|
||||
win = win->next;
|
||||
|
||||
if (win && ev.type == ClientMessage && ev.xclient.message_type == xvar->wm_protocols && ev.xclient.data.l[0] == xvar->wm_delete_window && win->hooks[DestroyNotify].hook)
|
||||
win->hooks[DestroyNotify].hook(win->hooks[DestroyNotify].param);
|
||||
if (win && ev.type < MLX_MAX_EVENT && win->hooks[ev.type].hook)
|
||||
mlx_int_param_event[ev.type](xvar, &ev, win);
|
||||
}
|
||||
XSync(xvar->display, False);
|
||||
if (xvar->loop_hook)
|
||||
xvar->loop_hook(xvar->loop_param);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user