-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 922fdfa
Showing
18 changed files
with
1,337 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
*.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Epitech projects | ||
|
||
Some of my student projects I made while studying at [Epitech](https://www.epitech.eu/). | ||
|
||
- [FDF - Fil de fer](fdf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## | ||
## Makefile for makefile in /home/drain_a//tps/i_graph/fdf | ||
## | ||
## Made by arnaud drain | ||
## Login <[email protected]> | ||
## | ||
## Started on Thu Nov 22 20:06:27 2012 arnaud drain | ||
## Last update Sun Dec 9 22:46:12 2012 arnaud drain | ||
## | ||
|
||
# Updated during refacto for MacOS (post-Epitech) | ||
|
||
CC = cc | ||
|
||
NAME = fdf | ||
|
||
SRCS = src/main.c \ | ||
src/gere.c \ | ||
src/fdf.c \ | ||
src/lib.c \ | ||
src/my_str_to_inttab.c \ | ||
src/get_next_line.c \ | ||
src/draw.c | ||
|
||
OBJS = $(SRCS:.c=.o) | ||
|
||
RM = rm -f | ||
|
||
INC = -I/usr/X11/include -Iinclude | ||
|
||
CFLAGS = $(INC) | ||
|
||
LDFLAGS = -L/usr/X11 -L/usr/X11/lib -lXext -lX11 -lmlx | ||
|
||
all: $(NAME) | ||
|
||
$(NAME): $(OBJS) | ||
$(CC) -o $(NAME) $(OBJS) $(LDFLAGS) | ||
|
||
clean: | ||
$(RM) $(OBJS) | ||
|
||
fclean: clean | ||
$(RM) $(NAME) | ||
|
||
re: fclean all | ||
|
||
.PHONY: all clean fclean re |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# FDF - Fil de fer | ||
|
||
Project from first year in Epitech, made in C using the [MinilibX](https://github.com/42Paris/minilibx-linux) | ||
|
||
## Installation | ||
|
||
### MacOS | ||
|
||
1. Install the [MinilibX](https://github.com/42Paris/minilibx-linux) to `/usr/X11/` | ||
2. Run `make` | ||
3. Launch project with input file `./fdf inputs/input1.fdf` | ||
|
||
## Screenshots | ||
|
||
 | ||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
** get_next_line.h for get_next_line in /home/drain_a//rendu_local/get_next_line | ||
** | ||
** Made by arnaud drain | ||
** Login <[email protected]> | ||
** | ||
** Started on Fri Nov 16 17:14:39 2012 arnaud drain | ||
** Last update Sun Dec 9 20:22:10 2012 arnaud drain | ||
*/ | ||
|
||
#ifndef HEADER_H_ | ||
# define HEADER_H_ | ||
|
||
#define READ (5000) | ||
#define SIZE_X (1000) | ||
#define SIZE_Y (1000) | ||
|
||
typedef struct s_coord | ||
{ | ||
int x; | ||
int y; | ||
} t_coord; | ||
|
||
typedef struct s_info | ||
{ | ||
void *mlx_ptr; | ||
void *win_ptr; | ||
void *img_ptr; | ||
} t_info; | ||
|
||
typedef struct s_vars | ||
{ | ||
int scale; | ||
int x; | ||
int y; | ||
int up; | ||
int left; | ||
int const1; | ||
int const2; | ||
t_info *info; | ||
int **tab; | ||
} t_vars; | ||
|
||
char *get_next_line(int fd); | ||
int **create_table(int fd); | ||
int gere_key(int keycode, t_vars *vars); | ||
int gere_expose(t_info *info); | ||
char *add_str_to_str(char *ret, char *buffer); | ||
|
||
/* | ||
** Added during refacto for MacOS (post-Epitech) | ||
*/ | ||
int draw_graph(int **tab, t_vars *vars); | ||
int my_putstr(char *str); | ||
int nb_int(char *str); | ||
int my_strlen(char *str); | ||
void set_vars(t_vars *vars, int **tab); | ||
void my_line_put_to_image(t_coord *pos1, t_coord *pos2, void *img, int col); | ||
int my_get_nbr(char *str); | ||
int arrondi(char *str); | ||
|
||
#endif /* !HEADER_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
0 0 0 0 0 0 0 0 0 0 | ||
0 10 10 10 10 10 10 10 10 0 | ||
0 1 20 15 12 15 17 20 10 0 | ||
0 10 15 10 12 15 15 15 10 0 | ||
0 5 15 10 12 15 15 13 10 0 | ||
0 5 10 5 7 12 12 12 10 0 | ||
0 5 7 1 2 7 5 5 7 0 | ||
0 3 0 0 1 2 2 2 5 0 | ||
0 1 0 0 0 0 0 0 3 0 | ||
0 0 0 0 0 0 0 0 0 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 50 50 0 0 0 0 0 0 0 50 50 50 0 0 0 0 0 | ||
0 0 0 50 50 0 0 0 0 0 0 50 50 50 50 50 0 0 0 0 | ||
0 0 0 50 50 0 0 0 0 0 0 50 50 0 50 50 50 0 0 0 | ||
0 0 0 50 50 0 0 0 0 0 0 50 50 0 0 50 50 0 0 0 | ||
0 0 0 50 50 0 0 0 0 0 0 50 50 0 0 50 50 0 0 0 | ||
0 0 0 50 50 0 0 0 0 0 0 0 0 0 0 50 50 0 0 0 | ||
0 0 0 50 50 50 50 50 0 0 0 0 0 0 50 50 50 0 0 0 | ||
0 0 0 50 50 50 50 50 0 0 0 0 0 50 50 50 0 0 0 0 | ||
0 0 0 50 50 50 50 50 0 0 0 0 50 50 50 0 0 0 0 0 | ||
0 0 0 0 0 50 50 0 0 0 0 50 50 50 0 0 0 0 0 0 | ||
0 0 0 0 0 50 50 0 0 0 0 50 50 0 0 0 0 0 0 0 | ||
0 0 0 0 0 50 50 0 0 0 0 50 50 50 50 50 50 0 0 0 | ||
0 0 0 0 0 50 50 0 0 0 0 50 50 50 50 50 50 0 0 0 | ||
0 0 0 0 0 50 50 0 0 0 0 50 50 50 50 50 50 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
** img1.c for tp in /home/drain_a//tps/i_graph/tp2 | ||
** | ||
** Made by arnaud drain | ||
** Login <[email protected]> | ||
** | ||
** Started on Thu Nov 15 12:31:15 2012 arnaud drain | ||
** Last update Sat Dec 8 11:38:33 2012 arnaud drain | ||
*/ | ||
|
||
#include <mlx.h> | ||
#include <stdlib.h> | ||
#include "header.h" | ||
|
||
int my_pixel_put_to_image(int x, int y, void *img_ptr, int col) | ||
{ | ||
char *data; | ||
char *color; | ||
int bpp; | ||
int sizeline; | ||
int endian; | ||
int pos; | ||
int i; | ||
|
||
color = &col; | ||
data = mlx_get_data_addr(img_ptr, &bpp, &sizeline, &endian); | ||
if (x <= 0 || y <= 0 || x >= SIZE_X || y >= SIZE_Y) | ||
return (1); | ||
pos = (sizeline * y) + (x * (bpp / 8)); | ||
i = 0; | ||
while (i < (bpp / 8)) | ||
{ | ||
data[pos + i] = color[i]; | ||
i = i + 1; | ||
} | ||
return (0); | ||
} | ||
|
||
void draw_cas_un(t_coord *pos1, t_coord *pos2, void *img, int col) | ||
{ | ||
int x; | ||
int y; | ||
t_coord *tmp; | ||
|
||
if (pos1->x > pos2->x) | ||
{ | ||
tmp = pos1; | ||
pos1 = pos2; | ||
pos2 = tmp; | ||
} | ||
x = pos1->x; | ||
while (x <= pos2->x) | ||
{ | ||
y = pos1->y + (pos2->y - pos1->y) * (x - pos1->x) / (pos2->x - pos1->x); | ||
my_pixel_put_to_image(x, y, img, col); | ||
x = x + 1; | ||
} | ||
} | ||
|
||
void draw_cas_deux(t_coord *pos1, t_coord *pos2, void *img, int col) | ||
{ | ||
int x; | ||
int y; | ||
t_coord *tmp; | ||
|
||
if (pos1->y > pos2->y) | ||
{ | ||
tmp = pos1; | ||
pos1 = pos2; | ||
pos2 = tmp; | ||
} | ||
y = pos1->y; | ||
while (y <= pos2->y) | ||
{ | ||
x = pos1->x + (pos2->x - pos1->x) * (y - pos1->y) / (pos2->y - pos1->y); | ||
my_pixel_put_to_image(x, y, img, col); | ||
y = y + 1; | ||
} | ||
} | ||
|
||
void my_line_put_to_image(t_coord *pos1, t_coord *pos2, void *img, int col) | ||
{ | ||
int width; | ||
int height; | ||
|
||
if (pos1->x > pos2->x) | ||
width = pos1->x - pos2->x; | ||
else | ||
width = pos2->x - pos1->x; | ||
if (pos1->y > pos2->y) | ||
height = pos1->y - pos2->y; | ||
else | ||
height = pos2->y - pos1->y; | ||
if (width > height) | ||
draw_cas_un(pos1, pos2, img, col); | ||
else | ||
draw_cas_deux(pos1, pos2, img, col); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
** fdf.c for fdf in /home/drain_a//tps/i_graph/fdf | ||
** | ||
** Made by arnaud drain | ||
** Login <[email protected]> | ||
** | ||
** Started on Thu Nov 22 19:48:39 2012 arnaud drain | ||
** Last update Sun Dec 9 22:46:01 2012 arnaud drain | ||
*/ | ||
|
||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <mlx.h> | ||
#include "header.h" | ||
|
||
int calc_pos(int x, int y, int z, t_vars *vars) | ||
{ | ||
int res; | ||
|
||
if (z <= 0) | ||
{ | ||
res = z + vars->const1 / 2 * vars->scale * x / 100; | ||
res = res + vars->const2 / 2 * vars->scale * y / 100 + vars->up; | ||
} | ||
else | ||
{ | ||
res = vars->const1 * x * vars->scale / 100; | ||
res = res - vars->const2 * y * vars->scale / 100 + vars->left; | ||
} | ||
return (res); | ||
} | ||
|
||
int find_coord(t_coord **pos1, t_coord **pos2, int **tab, t_vars *vars) | ||
{ | ||
int x; | ||
int y; | ||
int z; | ||
int color; | ||
|
||
color = mlx_get_color_value(vars->info->mlx_ptr, 0x0000ff); | ||
if ((*pos1 = malloc(sizeof(t_coord))) == NULL) | ||
return (1); | ||
if ((*pos2 = malloc(sizeof(t_coord))) == NULL) | ||
return (1); | ||
x = vars->x; | ||
y = vars->y; | ||
z = -tab[y][x]; | ||
pos1[0]->y = calc_pos(x, y, z, vars); | ||
pos1[0]->x = calc_pos(x, y, 1, vars); | ||
pos2[0]->x = calc_pos(x, y + 1, 1, vars); | ||
if (tab[y + 1] != NULL) | ||
{ | ||
z = -tab[y + 1][x]; | ||
pos2[0]->y = calc_pos(x, y + 1, z, vars); | ||
my_line_put_to_image(*pos1, *pos2, vars->info->img_ptr, color); | ||
} | ||
return (0); | ||
} | ||
|
||
void find_coord2(t_coord *pos1, t_coord *pos2, int **tab, t_vars *vars) | ||
{ | ||
int x; | ||
int y; | ||
int z; | ||
int color; | ||
|
||
color = mlx_get_color_value(vars->info->mlx_ptr, 0x0000ff); | ||
x = vars->x; | ||
y = vars->y; | ||
z = -tab[y][x + 1]; | ||
if (z <= 0) | ||
pos2->y = calc_pos(x + 1, y, z, vars); | ||
pos2->x = calc_pos(x + 1, y, 1, vars); | ||
if (tab[y][x + 1] >= 0) | ||
my_line_put_to_image(pos1, pos2, vars->info->img_ptr, color); | ||
} | ||
|
||
int draw_graph(int **tab, t_vars *vars) | ||
{ | ||
t_coord *pos1; | ||
t_coord *pos2; | ||
int x; | ||
int y; | ||
|
||
x = vars->x; | ||
y = vars->y; | ||
if (find_coord(&pos1, &pos2, tab, vars) == 1) | ||
return (1); | ||
find_coord2(pos1, pos2, tab, vars); | ||
vars->y = y + 1; | ||
if (tab[y + 1] != NULL) | ||
draw_graph(tab, vars); | ||
else | ||
{ | ||
vars->y = 0; | ||
vars->x = x + 1; | ||
if (tab[0][x + 1] >= 0) | ||
draw_graph(tab, vars); | ||
} | ||
free(pos1); | ||
free(pos2); | ||
return (0); | ||
} |
Oops, something went wrong.