Advertisement
LilChicha174

Untitled

Apr 24th, 2022
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.72 KB | None | 0 0
  1. void draw_Circle(struct Png *image, int x0, int y0, int line_fat, int width_pixel, int Red, int Green, int Blue) {
  2.     int x = 0;
  3.     int radius = line_fat / 2;
  4.     int y = radius;
  5.     int start = y0 - radius;
  6.     int end = y0 + radius;
  7.     int delta = 1 - 2 * radius;
  8.     int error;
  9.     while(y >= 0) {
  10.         png_byte *row = image->row_pointers[y0 + y];
  11.         png_byte *ptr = &(row[(x0 + x) * width_pixel]);
  12.         ptr[0] = Red;
  13.         ptr[1] = Green;
  14.         ptr[2] = Blue;
  15.  
  16.         png_byte *row1 = image->row_pointers[y0 - y];
  17.         png_byte *ptr1 = &(row1[(x0 + x) * width_pixel]);
  18.         ptr1[0] = Red;
  19.         ptr1[1] = Green;
  20.         ptr1[2] = Blue;
  21.  
  22.         png_byte *row2 = image->row_pointers[y0 + y];
  23.         png_byte *ptr2 = &(row2[(x0 - x) * width_pixel]);
  24.         ptr2[0] = Red;
  25.         ptr2[1] = Green;
  26.         ptr2[2] = Blue;
  27.  
  28.         png_byte *row3 = image->row_pointers[y0 - y];
  29.         png_byte *ptr3 = &(row3[(x0 - x) * width_pixel]);
  30.         ptr3[0] = Red;
  31.         ptr3[1] = Green;
  32.         ptr3[2] = Blue;
  33.         error = 2 * (delta + y) - 1;
  34.         while(start <= y0) {
  35.             for (int i = abs(x - x0); i < (x + x0); i++) {
  36.                 png_byte *row4 = image->row_pointers[start];
  37.                 png_byte *ptr4 = &(row4[i * width_pixel]);
  38.                 ptr4[0] = Red;
  39.                 ptr4[1] = Green;
  40.                 ptr4[2] = Blue;
  41.  
  42.                 png_byte *row5 = image->row_pointers[end];
  43.                 png_byte *ptr5 = &(row5[i * width_pixel]);
  44.                 ptr5[0] = Red;
  45.                 ptr5[1] = Green;
  46.                 ptr5[2] = Blue;
  47.             }
  48.             if(error > 0) {
  49.                 start++;
  50.                 end--;
  51.             }
  52.             break;
  53.         }
  54.         if(delta < 0 && error <= 0) {
  55.             ++x;
  56.             delta += 2 * x + 1;
  57.             continue;
  58.         }
  59.         error = 2 * (delta - x) - 1;
  60.         if(delta > 0 && error > 0) {
  61.             --y;
  62.             delta += 1 - 2 * y;
  63.             continue;
  64.         }
  65.         ++x;
  66.         delta += 2 * (x - y);
  67.         --y;
  68.     }
  69. }
  70.  
  71. void paint_line(struct Png *image, int width_pixel, int x0, int y0, int x1, int y1, int line_fat, int Red, int Green, int Blue){
  72.     int A, B, sign;
  73.     A = y1 - y0;
  74.     B = x0 - x1;
  75.     if (abs(A) > abs(B)) sign = 1;
  76.     else sign = -1;
  77.     int signa, signb;
  78.     if (A < 0) signa = -1;
  79.     else signa = 1;
  80.     if (B < 0) signb = -1;
  81.     else signb = 1;
  82.     int f = 0;
  83.     png_byte *row = image->row_pointers[y0];
  84.     png_byte *ptr = &(row[x0 * width_pixel]);
  85.     ptr[0] = Red;
  86.     ptr[1] = Green;
  87.     ptr[2] = Blue;
  88.     draw_Circle(image, x0, y0, line_fat, width_pixel, Red, Green, Blue);
  89.     int x = x0, y = y0;
  90.     if (sign == -1){
  91.         do {
  92.             f += A * signa;
  93.             if (f > 0)
  94.             {
  95.                 f -= B * signb;
  96.                 y += signa;
  97.             }
  98.             x -= signb;
  99.             png_byte *row1 = image->row_pointers[y];
  100.             png_byte *ptr1 = &(row1[x * width_pixel]);
  101.             ptr1[0] = Red;
  102.             ptr1[1] = Green;
  103.             ptr1[2] = Blue;
  104.             draw_Circle(image, x, y, line_fat, width_pixel, Red, Green, Blue);
  105.         } while (x != x1 || y != y1);
  106.     }
  107.     else
  108.     {
  109.         do {
  110.             f += B * signb;
  111.             if (f > 0) {
  112.                 f -= A * signa;
  113.                 x -= signb;
  114.             }
  115.             y += signa;
  116.             png_byte *row2 = image->row_pointers[y];
  117.             png_byte *ptr2 = &(row2[x * width_pixel]);
  118.             ptr2[0] = Red;
  119.             ptr2[1] = Green;
  120.             ptr2[2] = Blue;
  121.             draw_Circle(image, x, y, line_fat, width_pixel, Red, Green, Blue);
  122.         } while (x != x1 || y != y1);
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement