void tekline(t_bunny_pixelarray *pix, t_bunny_position *pos, unsigned int color) { t_bunny_position current; float pente; current.x = pos[0].x; current.y = pos[0].y; pente = get_pente(pos); if ((pente >= -1) && (pente <= 1)) while (current.x != pos[1].x) { (pos[1].x > pos[0].x) ? (current.x += 1) : (current.x -= 1); current.y = pos[0].y + ((current.x - pos[0].x) * pente); tekpixel(pix, ¤t, color); } else { while (current.y != pos[1].y) { (pos[1].y > pos[0].y) ? (current.y += 1) : (current.y -= 1); current.x = pos[0].x + ((current.y - pos[0].y) * (1 / pente)); tekpixel(pix, ¤t, color); } } }
void tekline(t_bunny_pixelarray *pix, t_bunny_position *pos, t_color *color) { float a; float b; int c; a = (float)(pos[1].y - pos[0].y) / (float)(pos[1].x - pos[0].x); b = (float)(pos[0].y - a * pos[0].x); while (pos[0].x != pos[1].x) { tekpixel(pix, pos, &color[0]); pos[0].x += ((pos[0].x > pos[1].x) ? -1 : 1); c = a * pos[0].x + b; while (pos[0].y != c) { pos[0].y += (pos[0].y == c) ? 0 : ((pos[0].y < c) ? 1 : -1); tekpixel(pix, pos, &color[0]); } } while (pos[0].y != pos[1].y && pos[0].x == pos[1].x) { tekpixel(pix, pos, &color[0]); pos[0].y += ((pos[0].y == pos[1].y) ? 0 : ((pos[0].y < pos[1].y) ? 1 : -1)); } }
void tekcircle_to_pix(t_bunny_pixelarray *pix, unsigned int color, float rad, t_bunny_position *pos) { float teta; t_bunny_position pos_c; float width; float height; teta = 0; width = rad * pix->clipable.buffer.width / 2; height = rad * pix->clipable.buffer.height / 2; while (teta <= 90) { pos_c.x = width * cos(teta * M_PI / 180) + pos->x; pos_c.y = height * sin(teta * M_PI / 180) + pos->y; tekpixel(pix, &pos_c, color); pos_c.y = 2 * pos->y - (pos_c.y); tekpixel(pix, &pos_c, color); pos_c.x = 2 * pos->x - (pos_c.x); tekpixel(pix, &pos_c, color); pos_c.y = 2 * pos->y - pos_c.y; tekpixel(pix, &pos_c, color); teta = teta + 0.1; } }
void tekline2(t_bunny_pixelarray *pix, t_bunny_position *pos, int *coords, t_color *color) { int i; int cumul; t_color *col; cumul = coords[5] / 2; i = 1; while (i <= coords[5]) { pos[0].y += coords[3]; cumul += coords[4]; if (cumul >= coords[5]) { cumul -= coords[5]; pos[0].x += coords[2]; } col = tekline_colorconvert(i, coords[5], color); tekpixel(pix, pos, col); bunny_free(col); i++; } }
static int aff_scrolling(t_bunny_pixelarray *pix, t_bunny_pixelarray *img, t_bunny_position *pos, int line) { t_color color; t_bunny_position bis; int printed; printed = 0; while (line >= 0 && pos[1].x >= 0) { while (pos[1].x >= 0) { color.full = pl_get_color(img, pos[1].x, pos[1].y); if (color.argb[ALPHA_CMP] > 0) { bis.x = (pos[0].x + pos[1].x) % WIDTH; bis.y = (pos[0].x + pos[1].y) % WIDTH; tekpixel(pix, &bis, color.full); (line == 0 ? scrollprinter(pix, &bis, color.full) : 0); } pos[1].x -= 1; } pos[1].y -= 1; pos[1].x = img->clipable.buffer.width; line -= 1; printed += 1; } return (printed); }
t_bunny_pixelarray *load_bmp(t_data *data, const char *name) { int fd; int readed; t_bunny_position pos; if ((fd = open(name, O_RDONLY)) == -1) return (NULL); if ((readed = read(fd, &data->bmp, 54)) == -1) return (NULL); data->image = bunny_new_pixelarray(data->bmp.width, data->bmp.height); pos.y = data->bmp.height - 1; while (pos.y != -1) { pos.x = 0; while (readed > 0 && pos.x != data->bmp.width) { pos.x += 1; if ((read(fd, data->buffer, (data->bmp.bits / 8))) == -1) return (NULL); col_tek(data); tekpixel(data->image, pos, data->col_image); } pos.y--; } return (data->image); }
void paint_circle(t_bunny_position *pos, int radius, t_bunny_pixelarray *pix, t_color *color) { int x; int y; int corr; t_bunny_position *coord; y = -radius; coord = bunny_malloc(sizeof(coord)); while (y <= radius) { x = -radius - 1; corr = 0; while (++x <= radius) { if (x * x + y * y <= radius * radius) { corr = 1; coord->x = pos->x + x; coord->y = pos->y + y; tekpixel(pix, coord, color); } else if (corr == 1) x = radius; } y++; } }
void bmp_to_pixel(int fd, t_bunny_pixelarray *pix, t_bitmap_header *bitmap) { t_color color; t_bunny_position pos; pos.y = pix->clipable.clip_height - 1; while (pos.y >= 0) { pos.x = 0; while (pos.x < pix->clipable.clip_width) { read(fd, &color.argb[2], sizeof(unsigned char)); read(fd, &color.argb[1], sizeof(unsigned char)); read(fd, &color.argb[0], sizeof(unsigned char)); if (bitmap->bitsperpixels == 32) read(fd, &color.argb[3], sizeof(unsigned char)); tekpixel(pix, &pos, &color); ++pos.x; } --pos.y; } aff_header(bitmap); }
void repeatImage(t_bunny_pixelarray *src, t_bunny_pixelarray *dest, double z) { t_ivec2 o; t_ivec2 incr; t_ivec2 dim; t_color color; t_ivec2 pos; o = ivec2((dest->clipable.clip_width - (int)(src->clipable.clip_width * z)) / 2, (dest->clipable.clip_height - (int)(src->clipable.clip_height * z)) / 2); dim = ivec2(src->clipable.clip_width, src->clipable.clip_height); dim = multiVec2(dim, z); while ((o.x > 0) ? (o.x -= dim.x) : 0); while ((o.y > 0) ? (o.y -= dim.y) : 0); incr.y = -1; while (++incr.y < dest->clipable.clip_height && (incr.x = -1)) while (++incr.x < dest->clipable.clip_width) { pos = ivec2((int)((incr.x - o.x) % dim.x / z), (int)((incr.y - o.y) % dim.y / z)); color.full = getPixel(src, pos); tekpixel(dest, &incr, &color); } }
void rotateImage(t_bunny_pixelarray *s, t_bunny_pixelarray *d, double r) { t_mat3 m; t_ivec2 incr; t_color color; t_ivec2 v[3]; t_vec3 tmp; v[0] = ivec2(d->clipable.clip_width / 2, d->clipable.clip_height / 2); v[2] = subiVec2(v[0], ivec2(s->clipable.clip_width / 2.0, s->clipable.clip_height / 2.0)); m = mat3(); translate3(&m, to_vec2(v[0])); rotate3D(&m, vec3(0, 0, -r)); translate3(&m, vec2(-v[0].x, -v[0].y)); incr.y = -1; while (++incr.y < d->clipable.clip_height) { incr.x = -1; while (++incr.x < d->clipable.clip_width) { tmp = multMatVec3(&m, vec3(incr.x, incr.y, 1)); v[1] = to_ivec2(vec2(tmp.x, tmp.y)); color.full = getPixel(s, subiVec2(v[1], v[2])); tekpixel(d, &incr, &color); } } }
void set_color(t_fire *fire) { int i; int j; j = HEIGHT - 1; while (j >= 1) { i = 0; while (i < WIDTH) { fire->anim[j][i] += (float)(fire->anim[j][i - 1] / 8); fire->anim[j][i] += (float)(fire->anim[j][i + 1] / 8); fire->anim[j][i] += (float)(fire->anim[j + 1][i - 1] / 8); fire->anim[j][i] += (float)(fire->anim[j - 1][i + 1] / 8); fire->anim[j][i] += (float)(fire->anim[j + 2][i - 1] / 8); fire->anim[j][i] += (float)(fire->anim[j + 2][i] / 8); fire->anim[j][i] += (float)(fire->anim[j + 2][i + 1] / 8); fire->anim[j][i] /= (float)1.85; fire->pos.x = i; fire->pos.y = j; tekpixel(fire->pix, &fire->pos, fire->gradient[fire->anim[j][i]]); i += 1; } j -= 1; } }
void tektranspa(t_bunny_pixelarray *pix, t_bunny_position *pos, t_color *color) { t_color prev; if (color->argb[3] == 255) { tekpixel(pix, pos, color); return; } if (pos->x < pix->clipable.clip_width && pos->y < pix->clipable.clip_height && pos->x >= 0 && pos->y >= 0) { prev = ((t_color *)pix->pixels)[pos->x + pix->clipable.clip_width * pos->y]; prev.argb[0] = (float)prev.argb[0] * ((255 - (float)color->argb[3]) / 255) + ((float)color->argb[0] * ((float)color->argb[3] / 255)); prev.argb[1] = (float)prev.argb[1] * ((255 - (float)color->argb[3]) / 255) + ((float)color->argb[1] * ((float)color->argb[3] / 255)); prev.argb[2] = (float)prev.argb[2] * ((255 - (float)color->argb[3]) / 255) + ((float)color->argb[2] * ((float)color->argb[3] / 255)); prev.argb[3] = 255; ((t_color *)pix->pixels)[pos->x + pix->clipable.clip_width * pos->y] = prev; } }
int pos_pix(TBX *pix, int x, int y, int color) { TBP pos; t_color col[1]; pos.x = x; pos.y = y; col[0].full = color; tekpixel(pix, &pos, col); return (0); }
static void red_surround(t_bunny_pixelarray *pix) { t_bunny_position pos; t_color c; c.full = RED; pos.x = 0; pos.y = 0; while (pos.x++ < pix->clipable.clip_width) tekpixel(pix, &pos, &c); pos.x -= 2; while (pos.y++ < pix->clipable.clip_height) tekpixel(pix, &pos, &c); pos.y -= 2; while (pos.x-- > 0) tekpixel(pix, &pos, &c); pos.x += 1; while (pos.y-- > 0) tekpixel(pix, &pos, &c); }
static void scrollprinter(t_bunny_pixelarray *pix, t_bunny_position *pos, unsigned int color) { while (pos->x < WIDTH && pos->y > 0) { tekpixel(pix, pos, color); pos->x += 1; pos->y -= 1; } }
void my_draw(t_wolf *wolf, t_bunny_pixelarray *pix, int x) { t_bunny_position pos[1]; int y; t_color color[1]; y = wolf->draw_start; pos[0].x = x; color[0] = get_wallcolor(wolf); while (y <= wolf->draw_end) { pos[0].y = y; if (wolf->map[wolf->mapX][wolf->mapY] == 2) tekpixel(pix, &pos[0], &color[0]); else if (wolf->side == 0) tekpixel(pix, &pos[0], &color[0]); else tekpixel(pix, &pos[0], &color[0]); y = y + 1; } }
void tekline(t_bunny_pixelarray *pix, t_bunny_position *pos, t_color *color) { t_bunny_position c[4]; set_tab_drawline(c, pos[0], pos[1]); tekpixel(pix, &pos[0], color); if (c[0].x >= c[0].y) draw_line_octan(pix, c, color); else draw_line_octan_inf(pix, c, color); }
void cone_to_pix(t_bunny_pixelarray *pix, t_cone *cone, t_bunny_position *pos, unsigned int color) { t_bunny_position pos_c; float angle; angle = cone->teta - 45; while (angle <= cone->teta + 45) { pos_c.x = cone->rad * cos(angle * M_PI / 180) + pos->x; pos_c.y = cone->rad * sin(angle * M_PI / 180) + pos->y; tekpixel(pix, &pos_c, color); angle = angle + 0.1; } }
void fill(t_bunny_pixelarray *pix, t_color *color) { t_bunny_position pixel; pixel.y = 0; while (pixel.y < pix->clipable.clip_height) { pixel.x = 0; while (pixel.x < pix->clipable.clip_width) { tekpixel(pix, &pixel, color); pixel.x++; } pixel.y++; } }
void set_background(t_bunny_pixelarray *pix, unsigned int color) { t_bunny_position pos; pos.y = 0; pos.x = 0; while (pos.y != pix->clipable.buffer.height) { while (pos.x != pix->clipable.buffer.width) { tekpixel(pix, &pos, color); pos.x = pos.x + 1; } pos.x = 0; pos.y = pos.y + 1; } }
void aa_supp(t_data *data) { t_bunny_position pos; t_color color; pos.x = 0; while (pos.x < WIN_X) { pos.y = 0; while (pos.y < WIN_Y) { color = get_color_sample(data, &pos); tekpixel(data->actual, &pos, &color); pos.y += 1; } pos.x += 1; } }
void teksquare(t_bunny_pixelarray *pix, int x, int y, unsigned int color) { t_bunny_position pos; x *= 10; y *= 10; pos.y = y; while (pos.y < y + 10) { pos.x = x; while (pos.x < x + 10) { tekpixel(pix, pos, color); pos.x++; } pos.y++; } }
void tekline(t_bunny_pixelarray *pix, t_bunny_position *pos, t_color *color) { int coords[6]; coords[0] = pos[1].x - pos[0].x; coords[1] = pos[1].y - pos[0].y; coords[2] = (coords[0] > 0) ? 1 : -1; coords[3] = (coords[1] > 0) ? 1 : -1; coords[4] = (coords[0] < 0) ? -(coords[0]) : coords[0]; coords[5] = (coords[1] < 0) ? -(coords[1]) : coords[1]; tekpixel(pix, pos, color); if (coords[4] > coords[5]) tekline1(pix, pos, coords, color); else tekline2(pix, pos, coords, color); }
void pos_pixel(t_form *form, t_bunny_pixelarray *pix) { t_obj *tmp; t_bunny_position pos; tmp = form->objs; while (tmp != NULL) { pos.x = tmp->a.pos.x; pos.y = tmp->a.pos.y; pos.x += form->x; pos.y += form->y; pos.x *= form->zoom; pos.y *= form->zoom; tekpixel(pix, &pos, &tmp->a.col); tmp = tmp->next; } }
void tekline_2(t_bunny_pixelarray *pix, t_bunny_position *pos, unsigned int color) { float coef; float b; coef = ((float)(pos[1].y - pos[0].y)) / ((float)(pos[1].x - pos[0].x)); coef = 1 / coef; b = (float)(pos[0].x - (coef * pos[0].y)); if (pos[0].y > pos[1].y) tekswap(&pos[0], &pos[1]); while (pos[0].y <= pos[1].y) { tekpixel(pix, pos, color); pos[0].y = pos[0].y + 1; pos[0].x = coef * pos[0].y + b; } }
void tekline_1(t_bunny_pixelarray *pix, t_bunny_position *pos, unsigned int color) { float coef; float b; coef = ((float)(pos[1].y - pos[0].y)) / ((float)(pos[1].x - pos[0].x)); b = (float)(pos[0].y - (coef * pos[0].x)); if (pos[0].x > pos[1].x) tekswap(&pos[0], &pos[1]); while (pos[0].x != pos[1].x) { tekpixel(pix, pos, color); pos[0].x = pos[0].x + 1; pos[0].y = coef * pos[0].x + b; color = color - 100; } }
static void print_scale(t_bunny_pixelarray *out, t_bunny_position *pos, t_color *color, int scale) { t_bunny_position bis; int yx[2]; yx[0] = -1; while (++yx[0] < scale) { yx[1] = -1; while (++yx[1] < scale) { bis.x = pos->x + yx[1]; bis.y = pos->y + yx[0]; tekpixel(out, &bis, color->full); } } }
static void draw_line_octan_inf(t_bunny_pixelarray *pix, t_bunny_position c[4], t_color *color) { int i; i = 0; while (i < c[0].y) { c[2].x = c[2].x + c[0].x; if (c[2].x >= c[0].y) { c[2].x = c[2].x - c[0].y; c[3].x = c[3].x + c[1].x; } c[3].y = c[3].y + c[1].y; tekpixel(pix, &c[3], color); i = i + 1; } }
void bmp_take_color(t_bunny_pixelarray *pix, t_bunny_position *pos, int fd) { t_color color; int len; len = 1; while (len > 0) { if ((len = read(fd, color.argb, 4)) == 4) { color = bmp_reverse_color(color); tekpixel(pix, pos, &color); } pos->x += 1; pos->y = (pos->x >= (pix->clipable).clip_width ? pos->y - 1 : pos->y); pos->x = (pos->x >= (pix->clipable).clip_width ? 0 : pos->x); } }
void setcolor(t_option *option) { t_bunny_position pos; int x; int y; y = 0; while (y < HEIGHT) { x = 0; while (x < WIDTH) { pos.x = x; pos.y = y; tekpixel(option->pix, &pos, &option->bg); x++; } y++; } }