static void ft_trait(int i, int j, t_mlx *mx, t_point *max) { t_p p; t_point point; t_point **map; map = mx->map; point.x = map[i][j].x; point.y = map[i][j].y; point.z = map[i][j].z; ft_iso1(&p, &point, mx, max); if (map[i + 1] && j < map[i + 1][0].len) { point.x = map[i + 1][j].x; point.y = map[i + 1][j].y; point.z = map[i + 1][j].z; ft_iso2(&p, &point, mx, max); ft_draw(&p, mx, map[i][j].z, point.z); } if (j + 1 < (map[i][0]).len) { point.x = map[i][j + 1].x; point.y = map[i][j + 1].y; point.z = map[i][j + 1].z; ft_iso2(&p, &point, mx, max); ft_draw(&p, mx, map[i][j].z, point.z); } }
void ft_iso(size_t x, size_t y, t_env *e) { e->x = (WIN_X / 5 * 2) + y * e->zoom + x * e->zoom + e->lr; e->y = (WIN_Y / 5 * 2) + y * e->zoom - x * e->zoom - e->tab[y][x] * e->height + e->ud; if (e->height_max == 0) e->height_max = 1; e->color = e->tab[y][x] * (0x3366ff / e->height_max) + e->contrast; if (x == 0) { e->y_prev = e->y; e->x_prev = e->x; } ft_draw(e->x, e->y, e); if (y > 0) { e->x_prev = (WIN_X / 5 * 2) + (y - 1) * e->zoom + x * e->zoom + e->lr; e->y_prev = (WIN_Y / 5 * 2) + (y - 1) * e->zoom - x * e->zoom - e->tab[y - 1][x] * e->height + e->ud; e->color = e->tab[y][x] * 0x3366ff / e->height_max + e->contrast; ft_draw(e->x, e->y, e); } e->y_prev = e->y; e->x_prev = e->x; }
int ft_expose_hook(t_env *env) { t_coord *ptr; t_coord *p; t_coord *tmp; ptr = ft_dup_struct(env); p = ptr; tmp = NULL; ft_bzero(env->data, WIN_X * WIN_Y * env->bpp / 8); while (ptr || tmp) { if (ptr && ptr->next) ft_draw(env, ptr, ptr->next); if (tmp && ptr) ft_draw(env, tmp, ptr); if (tmp) tmp = tmp->next; if (ptr && ptr->z == -1 && !tmp) tmp = p; if (ptr) ptr = ptr->next; } mlx_put_image_to_window(env->mlx, env->win, env->img, 0, 0); ft_destroy_struct(ptr); return (0); }
int main(void) { char *wd; char *wtf; char letter; int life; int success; char *tried; while(ft_wd_is_good(wd) != 1) { wd = ft_get_wd(); } ft_lwr_case(wd); tried = malloc(sizeof(char)); wtf = ft_prepare_str(wd); ft_hide(); life = 15; while (ft_game_over(wd, wtf) != 1 && life > 0) { ft_hide(); ft_draw(life); ft_putstr("Il te reste "); ft_putnbr(life); ft_putstr(" vies\n"); ft_putstr("Voici les lettres que tu as deja essaye :\n"); ft_putstr(tried); ft_putstr("\n\n"); ft_putstr("======> "); ft_putstr(wtf); ft_putstr("<======\n"); letter = ft_get_letter(); if ((letter >= 'a' && letter <= 'z') || letter == '-') { if (ft_is_tried(tried, letter)) success = ft_check_presence(letter, wtf, wd); if (ft_check_presence(letter, wtf, tried) == 0) tried = ft_add_letter(tried, letter); if (success == 0) life--; } ft_sort_alpha(tried); } if (life == 0) { ft_hide(); ft_draw(life); ft_putstr(" PERDU !\n\n\n"); ft_putstr(" Le mot mystere etait ==> "); ft_putstr(wd); ft_putchar('\n'); ft_putchar('\n'); ft_putchar('\n'); } return (0); }
void ft_browse_column(t_env *e, t_mand *man, int i) { int j; int c; double tmp; double sqzr; double sqzi; j = 0; while (j < e->height) { man->cr = i / man->zoomx + e->zone->x1; man->ci = j / man->zoomy + e->zone->y1; man->zr = 0; man->zi = 0; sqzr = man->zr * man->zr; sqzi = man->zi * man->zi; c = 0; while ((sqzr + sqzi <= 4 && sqzr + sqzi >= -4) && c < e->zone->cmax) { tmp = man->zr; man->zr = sqzr - sqzi + man->cr; man->zi = man->zi * tmp + man->zi * tmp + man->ci; sqzr = man->zr * man->zr; sqzi = man->zi * man->zi; c++; } ft_draw(e, c, i, j); j++; } }
int key_hook(int keycode, t_mlx *mlx) { double tab1[7]; double tab2[7]; mlx_clear_window(mlx->mlx, mlx->win); if (keycode == 53) exit(0); else if (keycode == 49 && mlx->f->nb == 1) ft_switch_julia(mlx, tab1, tab2, 0); else if (keycode == 69) mlx->iter = (mlx->iter < 8000) ? mlx->iter * 2 : mlx->iter; else if (keycode == 78) mlx->iter = (mlx->iter > 2) ? mlx->iter / 2 : mlx->iter; else if (keycode == 8) mlx->color++; else if (keycode == 3) mlx->freq = (mlx->freq < 200) ? mlx->freq * 2 : mlx->freq; else if (keycode == 2) mlx->freq = (mlx->freq > 0.1) ? mlx->freq / 2 : mlx->freq; key_hook2(keycode, mlx); ft_move(keycode, mlx); ft_draw(mlx); return (0); }
void ft_julia(t_env *env) { t_fract fract; fract.x = 0; while (fract.x < X_SIZE) { fract.y = 0; while (fract.y < Y_SIZE) { fract = ft_fract_julia(fract, fract.x, fract.y, env); fract.i = 0; while ((((fract.z_r * fract.z_r) + (fract.z_i * fract.z_i)) < 4) && (fract.i < IT_MAX)) { fract.tmp = fract.z_r; fract.z_r = ((fract.z_r * fract.z_r) - (fract.z_i * fract.z_i) + fract.c_r); fract.z_i = ((2 * fract.z_i * fract.tmp) + fract.c_i); fract.i++; } ft_draw(env, fract.x, fract.y, fract.i); fract.y++; } fract.x++; } }
int main(int ac, char **av) { t_env e; if (ac != 2) ft_error("Voir Usage a la compilation."); ft_getinput(&e, av[1]); if (!(e.mlx = mlx_init())) ft_error("mlx_init: Connexion au Xserver echouee."); if (!(e.win = mlx_new_window(e.mlx, WIDTH, HEIGHT, "fdf"))) ft_error("mlx_new_window: La fenetre n'a pas pu etre creee."); if (!(e.img = mlx_new_image(e.mlx, WIDTH, HEIGHT))) ft_error("mlx_new_image: L'image n'a pas pu etre creee."); if (!(e.table = mlx_get_data_addr(e.img, &e.bpp, &e.size, &e.endian))) ft_error("mlx_get_data_addr: Les donnees n'ont pas pu etre lues."); e.zoom = 10; e.r = 0xcc; e.g = 0xcc; e.b = 0xcc; ft_center(&e, 0, 0, 0); ft_draw(&e); mlx_expose_hook(e.win, &ft_exposehook, &e); mlx_mouse_hook(e.win, &ft_mousehook, &e); mlx_hook(e.win, KeyPress, KeyPressMask, &ft_keypress, &e); mlx_loop(e.mlx); return (0); }
static int ft_key_hook(int keycode, t_env *env) { if (keycode == 53) exit(0); else if (keycode == W) env->f.decal_y -= 10; else if (keycode == S) env->f.decal_y += 10; else if (keycode == A) env->f.decal_x -= 10; else if (keycode == D) env->f.decal_x += 10; else if (keycode == P && env->f.motion == 1) env->f.motion = 0; else if (keycode == P && env->f.motion == 0) env->f.motion = 1; else if (keycode == M && env->f.m == 0) env->f.m = 1; else if (keycode == M && env->f.m == 1) env->f.m = 0; else ft_key_hook_2(keycode, env); ft_draw(env); return (0); }
int main(int ac, char **av) { t_env e; if (ac == 2 && av) { if (!(e.mlx = mlx_init())) exit_gracefully("mlx_init: Connexion to Xserver failed."); if (!(e.win = mlx_new_window(e.mlx, WIDTH, HEIGHT, "Wolf3D"))) exit_gracefully("mlx_new_window: Could not create window."); if (!(e.img = mlx_new_image(e.mlx, WIDTH, HEIGHT))) exit_gracefully("mlx_new_image: Could not create image."); if (!(e.table = mlx_get_data_addr(e.img, &e.bpp, &e.size, &e.endian))) exit_gracefully("mlx_get_data_addr: Could not read data."); ft_count_columns(&e, av[1]); e.x = e.map_line / 2; e.y = e.map_col / 2; ft_line(&e, 1.2); ft_draw(&e); mlx_expose_hook(e.win, &ft_exposehook, &e); mlx_hook(e.win, KeyPress, KeyPressMask, &ft_keypress, &e); mlx_loop(e.mlx); } else exit_gracefully("\033[33mUsage : ./wolf3d <map.name>\033[0m"); return (0); }
int ft_keypress(int keycode, t_env *e) { if (keycode == 65307) exit_gracefully("You exited the program"); mlx_clear_window(e->mlx, e->win); ft_draw(e); return (0); }
void ft_draw_pt2d(t_env *env) { int i; i = 0; while (env->pt2d[i].x != 0) { ft_pixel_put_img(env, (env->pt2d[i].x + env->xvar), (env->pt2d[i].y + env->yvar), ft_color(env->pt2d[i])); if (i > 0 && env->pt2d[i].line == env->pt2d[i - 1].line) ft_draw(env->pt2d[i - 1], env->pt2d[i], env); if (env->pt2d[i].stay_high != NULL) ft_draw(env->pt2d[i], env->pt2d[i].stay_high[0], env); i++; } mlx_put_image_to_window(env->mlx, env->win, env->img.img_ptr, 0, 0); return ; }
void ft_raycaster(t_env *e) { e->x = 0; while (e->x < WIDTH) { ft_initray(e); ft_dda(e); ft_line(e); ft_draw(e); e->x++; } }
int main(int argc, char **argv) { t_ba ba; t_obj obj; int i; (void)argc; if (!(i = ft_select_env(argv, &obj))) return (0); ft_init_ptrfunc(&ba); if ((ba.mlx = mlx_init()) == NULL) { ft_putstr("mlx_init failed. Abort.\n"); exit(-1); } ba.wdw = mlx_new_window(ba.mlx, (WD_H / 2), (WD_W / 2), "RT - Mr Pickles"); ft_setimg(&ba); ft_draw(&ba, &obj); ba.loop = mlx_key_hook(ba.wdw, &ft_key_hook, &ba); ba.loop = mlx_expose_hook(ba.wdw, &ft_expose_hook, &ba); ba.loop = mlx_loop(ba.mlx); return (0); }
int main(int ac, char **av) { t_env env; (void)av; if (ac < 2) { ft_menu_shell(); return (0); } env.f = ft_init(av[1]); env.f.height = (env.f.x2 - env.f.x1) * env.f.zoom; env.f.width = (env.f.y2 - env.f.y1) * env.f.zoom; env.mlx = mlx_init(); env.win = mlx_new_window(env.mlx, env.f.height, env.f.width, "Fractol"); env.img = mlx_new_image(env.mlx, env.f.height, env.f.width); env = ft_get_data(&env); ft_draw(&env); mlx_key_hook(env.win, ft_key_hook, &env); mlx_mouse_hook(env.win, ft_mouse_hook, &env); mlx_hook(env.win, 6, (1L << 6), motion_hook, &env); mlx_loop(env.mlx); }
void ft_zoom_in(t_graph *graph) { graph->zoom = graph->zoom + graph->zoom_step; ft_draw(graph); }
void ft_move_up(t_graph *grp) { grp->y_offset = grp->y_offset - 5; ft_draw(grp); }
int loop_event(t_window *w) // fonction indispensable de la MLX (voir dans le main) { ft_draw(w); return (0); }
void ft_move_lft(t_graph *grp) { grp->x_offset = grp->x_offset - 5; ft_draw(grp); }