void draw_mandelbrot(t_env *e, t_fractal *f) { while (f->x++ < SCRX - 1) { while (f->y++ < SCRY - 1) { f->rc = f->min_x + (f->max_x - f->min_x) / SCRX * f->x; f->ic = f->min_y + (f->max_y - f->min_y) / SCRY * f->y; f->rz = 0.0; f->iz = 0.0; while (f->a < e->deep) { f->r = f->rz; f->i = f->iz; f->rz = f->r * f->r - f->i * f->i + f->rc; f->iz = 2.0 * f->r * f->i + f->ic; f->a++; } f->a = 0; if (f->rz * f->rz + f->iz * f->iz > 4.0) put_pixel(e, f); else put_pixel_to_img(e, f->x, f->y, BLACK + 50); } f->y = 0; } }
void floor_to_img(t_env *e, int y) { t_color color; int pos_texel_texture; int addr; pos_texel_texture = e->tex[5].sizeline * e->floor.tex_y + e->floor.tex_x * e->tex[5].opp; set_color_from_img(&color, e->tex[5].img_data, pos_texel_texture); addr = y * e->mlx_init.img.sizeline + e->x * e->mlx_init.img.opp; put_pixel_to_img(e, addr, color); }
int aff_pixel(int color, t_rtv1 *rt, int x, int y) { t_obj *tmp; int i; tmp = rt->start; i = 0; while (i < rt->lenght) { if (i == color) { put_pixel_to_img(rt->img->data, get_dot(x, y), get_color(tmp->color->r, tmp->color->v, tmp->color->b), rt->sbe->sizeline); return (0); } tmp = tmp->next; i++; } put_pixel_to_img(rt->img->data, get_dot(x, y), get_color(40, 40, 40), rt->sbe->sizeline); return (0); }
void draw_iso_dots(t_fdf *fdf, int *c, t_map *map, int i) { int color; (void)i; (void)map; color = c[6]; put_pixel_to_img(fdf, c[0], c[1], color); if (c[2]) bresenham_algo(fdf, c[2], c[3], c); if (c[4]) bresenham_algo(fdf, c[4], c[5], c); }
void put_pixel_perso(t_env *e, t_fractal *f) { int color; color = 0; if (f->iz > (0.04 + e->deep / 1000)) color = BLUE + e->deep; else if (f->iz <= (0.04 + e->deep / 1000) && f->iz >= (-0.04 + e->deep / 1000)) color = GREEN + e->deep; else if (f->iz < (-0.04 + e->deep / 1000)) color = RED + e->deep; put_pixel_to_img(e, f->x, f->y, color); }
void put_pixel(t_env *e, t_fractal *f) { int color; color = 0; if (f->iz > (4.0 + e->deep / 1000)) color = GREEN + e->frac->a / e->deep; else if (f->iz <= (4.0 + e->deep / 1000) && f->iz >= (-4.0 + e->deep / 1000)) color = BLUE + e->frac->a / e->deep; else if (f->iz < (-4.0 + e->deep / 1000)) color = RED + e->frac->a / e->deep; put_pixel_to_img(e, f->x, f->y, color); }
void bres_right(t_fdf *fdf, int *coords, int x, int y) { int i; coords[5] = coords[1] / 2; i = 1; while (i <= coords[1]) { y += coords[4]; coords[5] += coords[0]; if (coords[5] >= coords[1]) { coords[5] -= coords[1]; x += coords[3]; } put_pixel_to_img(fdf, x, y, coords[2]); i++; } }
void draw_wall_textured(t_env *e) { t_color color; int pos_texel_texture; int addr; int y; int d; y = e->wall.start; while (y <= e->wall.end) { d = y * 256 - SCREEN_H * 128 + e->wall.height * 128; e->texture.y = d * e->tex[e->texture.num].height / e->wall.height / 256; addr = y * e->mlx_init.img.sizeline + e->x * e->mlx_init.img.opp; pos_texel_texture = e->tex[e->texture.num].sizeline * e->texture.y + e->texture.x * e->tex[e->texture.num].opp; set_color_from_img(&color, e->tex[e->texture.num].img_data, pos_texel_texture); put_pixel_to_img(e, addr, color); y++; } }
void draw_perso(t_env *e, t_fractal *f) { while (f->x++ < SCRX - 1) { while (f->y++ < SCRY - 1) { f->rz = f->min_x + (f->max_x - f->min_x) / SCRX * f->x; f->iz = f->min_y + (f->max_y - f->min_y) / SCRY * f->y; while (f->rz * f->rz + f->iz * f->iz <= 4.0 && f->a < e->deep) { f->r = f->rz; f->rz = f->rz * f->rz - f->iz * f->iz + f->rc; f->iz = 2.0 * f->r * f->iz + f->ic; f->a++; } f->a = 0; if (f->rz * f->rz + f->iz * f->iz <= 4.0) put_pixel_perso(e, f); else put_pixel_to_img(e, f->x, f->y, WHITE); } f->y = 0; } }
void bresenham_algo(t_fdf *fdf, int xi, int yi, int *c) { int x; int y; int *coords; coords = (int*)malloc(sizeof(int) * 10); coords[8] = c[0]; coords[9] = c[1]; x = xi; y = yi; coords[0] = coords[8] - xi; coords[1] = coords[9] - yi; coords[3] = (coords[0] > 0) ? 1 : -1; coords[4] = (coords[1] > 0) ? 1 : -1; coords[0] *= coords[3]; coords[1] *= coords[4]; coords[2] = c[6]; put_pixel_to_img(fdf, x, y, c[6]); if (coords[0] > coords[1]) bres_left(fdf, coords, x, y); else bres_right(fdf, coords, x, y); }