Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void turn(struct Png *image, struct Png *image2, int width_pixel, int x1, int y1, int x2, int y2,
- int degree) {
- int x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4, x_new, y_new;
- x_1 = x1, y_1 = y2, x_2 = x1, y_2 = y1, x_3 = x2, y_3 = y1, x_4 = x2, y_4 = y2;
- int x_c = (x_1 + x_2 + x_3 + x_4) / 4;
- int y_c = (y_1 + y_2 + y_3 + y_4) / 4;
- for (int y = 0; y < image2->height; y++) {
- png_byte *row = image2->row_pointers[y];
- for (int x = 0; x < image2->width; x++) {
- png_byte *ptr = &(row[x * width_pixel]);
- if (is_inside(x, y, x_1, y_1, x_3, y_3)) {
- int way_x = x - x_c;
- int way_y = y - y_c;
- if (degree == 90) {
- x_new = x_c - way_y;
- y_new = y_c + way_x;
- paint_pixel(image, x_new, y_new, 3, ptr[0], ptr[1], ptr[2]);
- }
- if (degree == 180) {
- x_new = x_c - way_x;
- y_new = y_c - way_y;
- paint_pixel(image, x_new, y_new, 3, ptr[0], ptr[1], ptr[2]);
- }
- if (degree == 270) {
- x_new = x_c + way_y;
- y_new = y_c - way_x;
- paint_pixel(image, x_new, y_new, 3, ptr[0], ptr[1], ptr[2]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement