Skip to content

Commit

Permalink
Finally done . Added a little close window hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad abir Abbas committed Dec 10, 2022
0 parents commit 2de25c6
Show file tree
Hide file tree
Showing 74 changed files with 9,826 additions and 0 deletions.
113 changes: 113 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: mabbas <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/08/08 21:06:32 by mabbas #+# #+# #
# Updated: 2022/12/09 00:22:20 by mabbas ### ########.fr #
# #
# **************************************************************************** #

NAME = fractol
#define compiler and flags for Debugger
CC = gcc
CFLAGS = -Wall -Werror -Wextra -I ./includes/fractol.h

# Including the directories
LIBFT = ./libs/libft/
#MINILIBX = ./libs/minilibx-linux/libmlx.a
MLX := ./libs/minilibx-linux/

# SRCS = ./src
SRCS = $(wildcard ./src/*.c)
# Making it cross-platform
OS := $(shell uname -s)

# Choice for mac/linux version
ifeq ($(OS),Windows_NT)
NAME := $(addsuffix .exe, $(NAME))
else ifeq ($(OS), Darwin)
MLX_DIR = libs/minilibx-linux/libmlx.a
LIBFLAGS = -framework OpenGL -framework AppKit -lm -lmlx -I -L/libs/minilibx-linux/libmlx_linux.a
endif

OBJS = $(SRCS:.c=.o)
# Color Codes

SUBM_STATE := $(shell find libs/libft -type f && libs/minilibx-linux -type f)

ifeq ($(SUBM_STATE),)
SUBM_FLAG = submodule
else
SUBM_FLAG =
endif

NC := \033[m
B_RED := \033[1;31m
RED := \033[0;31m
B_GREEN := \033[1;32m
GREEN := \033[0;33m
B_BLUE := \033[1;34m
BLUE := \033[0;34m
PURPLE := \033[0;35m
WHCOLOR := \033[0;40m

##Check for Linux and run Valgrind when debugger on

UNAME = $(shell uname -s)

ifeq ($(UNAME),Linux)
VALGRIND = valgrind -q --leak-check=full --track-origin=yes
else
detected_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
endif

all: $(SUBM_FLAG) libft mlx $(NAME)

%.o : %.c
@$(CC) $(CFLAGS) -c $< -o $@

submodule:
git submodule init
git submodule update

libft:
@echo "____!!!$(BLUE)----- Compiling Libft------$(NC)"
@$(MAKE) -C $(LIBFT)
@$(MAKE) -C $(LIBFT) bonus
@echo "Compilation of Libft: \033[1;32mOK\033[m"


mlx:
@echo "____!!!$(RED)----- Compiling mlx ------$(NC)"
@$(MAKE) -C $(MLX)
@echo "Creation of MLX: \033[1;32mOK\033[m"



$(NAME): $(OBJS)
@$(CC) $(CFLAGS) $(OBJS) $(LIBFLAGS) $(MLX_DIR) $(LIBFT)libft.a -o $(NAME)
@echo "Compilation of Fractol: \033[1;32mSUCCESS\033[m"




# Clean up your trashes

clean:
@echo "$(GREEN)♻️ ${B_RED} Trashing Away objects..... $(GREEN)♻️ "
@rm -f $(OBJS)
@$(MAKE) -C $(LIBFT) clean
@$(MAKE) -C $(MLX) clean
@sleep 0.5
@echo " $(B_RED) Cleaning Done $(NC)"

fclean: clean
@rm -f $(NAME)
@echo "$(GREEN)♻️ ${B_RED} Trashing Away all objects and library...."

re: fclean all

.phony: all libft clean fclean mlx
Binary file added fractol
Binary file not shown.
102 changes: 102 additions & 0 deletions includes/fractol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mlx.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mabbas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/01 23:12:22 by mabbas #+# #+# */
/* Updated: 2022/12/08 14:17:25 by mabbas ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef FRACTOL_H
# define FRACTOL_H

# include <math.h>
# include <stdlib.h>
# include <unistd.h>
# include <pthread.h>
# include "./keys.h"
# include "../libs/minilibx-linux/mlx.h"
# include "../libs/libft/libft.h"

/** Defining the parameters of the window **/

# define WIDTH 800
# define HEIGHT 600

#define MLX_SYNC_IMAGE_WRITABLE 1
#define MLX_SYNC_WIN_FLUSH_CMD 2
#define MLX_SYNC_WIN_CMD_COMPLETED 3

/**
Struct for real and imaginary numbers **/
typedef struct s_oper
{
double r;
double i;
} t_oper;

/** Struct to draw images **/

typedef struct s_img
{
void *img;
char *data_addr;
int bpp;
int line_size;
int endian;
} t_img;

/** Struct to calculate fractals **/

typedef struct s_mlx
{
t_img *img;
void *mlx;
void *win;
int iter;
int iter_max;
int press;
int shift;
t_oper max;
t_oper min;
t_oper c;
t_oper k;
void (*eqn)(struct s_mlx *);

} t_mlx;

t_oper complex_init(double r, double i);
t_img *img_init(t_mlx *mlx);

void default_init(t_mlx *mlx);
int color_init(t_mlx *mlx);

int trgb_gen(int t, int r, int g, int b);
void recode_mlx_pixel_put(t_mlx *mlx, int x, int y, int color);
double lerp(double start, double end, double inter_coeff);

int ctrl_mouse(int key, int x, int y, t_mlx *mlx);
int keymap(int key, t_mlx *mlx);

void render_fractal(t_mlx *mlx);
void mandelbrot(t_mlx *mlx);
void julia(t_mlx *mlx);
void burning_ship(t_mlx *mlx);

void gui_init(t_mlx *mlx);

void arg_check(char *arg);
void help_options(void);

int change_julia(int x, int y, t_mlx *mlx);
int julia_key_press(int key, int x, int y, t_mlx *mlx);

void move_w_key(int key, t_mlx *mlx);
void shift_color(t_mlx *mlx);

int close_window(t_mlx *mlx);

#endif
70 changes: 70 additions & 0 deletions includes/keys.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* keys.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mabbas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 19:29:32 by mabbas #+# #+# */
/* Updated: 2022/12/09 01:10:18 by mabbas ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef KEYS_H
# define KEYS_H

# ifdef __linux__
# define K_ESC 65307
# define K_NUM_MULT 65450
# define K_NUM_DIV 65455
# define K_NUM_PLUS 65451
# define K_NUM_MINUS 65453
# define K_NUM_ENTER 65421
# define K_NUM_0 65438
# define K_UP 65362
# define K_DOWN 65364
# define K_LEFT 65361
# define K_RIGHT 65363
# define K_DIGIT_1 49
# define K_L 108
# else
/** define the parameter for keymaps **/

# define KEY_ESC 53
# define KEY_UP 126
# define KEY_DOWN 125
# define KEY_LEFT 123
# define KEY_RIGHT 124
# define KEY_ENTER 36
# define KEY_W 13
# define KEY_A 0
# define KEY_S 1
# define KEY_D 2
# define KEY_Z 6
# define KEY_X 7
# define KEY_Y 16
# define KEY_E 14
# define KEY_Q 12
# define KEY_C 8
# define KEY_G 5
# define KEY_H 4
# define KEY_SPACE 49
# define KEY_ONE 18
# define KEY_TWO 19
# define KEY_THREE 20
# define KEY_FOUR 21
# define KEY_FIVE 23
# define KEY_SIX 22
# define KEY_SEVEN 26
# define KEY_EIGHT 28
# define INF_C 0x36454f
# define PSY_C 0x654321
# define RED_C 0x0A0505
# define GREEN_C 0x050A05
# define BLUE_C 0x05050A
# define GREY_C 0x666666
# define NEWT_C 0x050A0F
# define THORN_C 0x08ED55

# endif
#endif
90 changes: 90 additions & 0 deletions libs/libft/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: mabbas <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/04/25 17:54:37 by mabbas #+# #+# #
# Updated: 2022/11/12 01:35:41 by mabbas ### ########.fr #
# #
# **************************************************************************** #

NAME = libft.a
#define compiler and flags
CC = gcc
CFLAGS = -Wall -Wextra -Werror
#Source Functions for the library
source = ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c \
ft_strlen.c ft_memcpy.c ft_memset.c ft_bzero.c \
ft_atoi.c ft_memmove.c ft_toupper.c \
ft_tolower.c ft_strlcpy.c ft_strlcat.c \
ft_memchr.c ft_strchr.c ft_memcmp.c ft_strrchr.c ft_strncmp.c ft_strnstr.c \
ft_calloc.c ft_strdup.c ft_substr.c ft_strjoin.c ft_strtrim.c ft_itoa.c \
ft_split.c ft_strmapi.c ft_striteri.c ft_putchar_fd.c ft_putstr_fd.c \
ft_putendl_fd.c ft_putnbr_fd.c

bonus_src = 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_lstmap.c

# The object files after compiling
objects = $(source:%.c=%.o)
objbonus = $(bonus_src:%.c=%.o)

all: $(NAME)

%.o : %.c
@$(CC) $(CFLAGS) -c $< -o $@

$(NAME): $(objects)
@echo "$$HEADER"
@$(CC) $(CFLAGS) -c $(source)
@ar rcs $(NAME) $(objects)

clean:
@rm -rf $(objects) $(objbonus)

fclean: clean
@echo "$$HEADER3"
@rm -rf $(NAME)


re: fclean all

bonus:
@echo "$$HEADER4"
@$(CC) $(CFLAGS) -c $(bonus_src)
@ar rcs $(NAME) $(objbonus)


.PHONY: all clean fclean re bonus





define HEADER

>>>>>>>--<<<<<Beware!! We are now Compiling <<<<<-->>>> !_!
“Fool! Nothing but black ink runs through my veins!”
― Hiromu Arakawa
endef
export HEADER

define HEADER3


░█████╗░░█████╗░██╗░░░██╗████████╗██╗░█████╗░███╗░░██╗██╗██╗
██╔══██╗██╔══██╗██║░░░██║╚══██╔══╝██║██╔══██╗████╗░██║██║██║
██║░░╚═╝███████║██║░░░██║░░░██║░░░██║██║░░██║██╔██╗██║██║██║
██║░░██╗██╔══██║██║░░░██║░░░██║░░░██║██║░░██║██║╚████║╚═╝╚═╝
╚█████╔╝██║░░██║╚██████╔╝░░░██║░░░██║╚█████╔╝██║░╚███║██╗██╗
░╚════╝░╚═╝░░╚═╝░╚═════╝░░░░╚═╝░░░╚═╝░╚════╝░╚═╝░░╚══╝╚═╝╚═╝
endef
export HEADER3

define HEADER4

█▓▒▒░░░<<-- 🅛 🅘 🅝 🅚 🅔 🅓 🅛 🅘 🅢 🅣 🅜 🅐 🅓 🅝 🅔 🅢 🅢 -->>░░░▒▒▓█
endef
export HEADER4
Loading

0 comments on commit 2de25c6

Please sign in to comment.