Advertisement
LilChicha174

Untitled

Jun 2nd, 2022
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.73 KB | None | 0 0
  1. void draw_Circle(struct Png *image, int x0, int y0, int line_fat, int width_pixel, int Red,
  2.                  int
  3.                  Green,
  4.                  int Blue) {
  5.     int x = 0;
  6.     int radius = line_fat / 2;
  7.     int y = radius;
  8.     int start = y0 - radius;
  9.     int end = y0 + radius;
  10.     int delta = 1 - 2 * radius;
  11.     int error;
  12.     while (y >= 0) {
  13.         paint_pixel(image, x0 + x, y0 + y, width_pixel, Red, Green, Blue);
  14.  
  15.         paint_pixel(image, x0 + x, y0 - y, width_pixel, Red, Green, Blue);
  16.  
  17.         paint_pixel(image, x0 - x, y0 + y, width_pixel, Red, Green, Blue);
  18.  
  19.         paint_pixel(image, x0 - x, y0 - y, width_pixel, Red, Green, Blue);
  20.  
  21.         error = 2 * (delta + y) - 1;
  22.         while (start <= y0) {
  23.             for (int i = abs(x - x0); i < (x + x0); i++) {
  24.                 paint_pixel(image, i, start, width_pixel, Red, Green, Blue);
  25.  
  26.                 paint_pixel(image, i, end, width_pixel, Red, Green, Blue);
  27.             }
  28.             if (error > 0) {
  29.                 start++;
  30.                 end--;
  31.             }
  32.             break;
  33.         }
  34.         if (delta < 0 && error <= 0) {
  35.             ++x;
  36.             delta += 2 * x + 1;
  37.             continue;
  38.         }
  39.         error = 2 * (delta - x) - 1;
  40.         if (delta > 0 && error > 0) {
  41.             --y;
  42.             delta += 1 - 2 * y;
  43.             continue;
  44.         }
  45.         ++x;
  46.         delta += 2 * (x - y);
  47.         --y;
  48.     }
  49. }
  50.  
  51. void paint_line(struct Png *image, int width_pixel, int x0, int y0, int x1, int y1, int line_fat,
  52.                 int Red, int Green, int Blue) {
  53.     int A, B, sign;
  54.     A = y1 - y0;
  55.     B = x0 - x1;
  56.     if (abs(A) > abs(B)) sign = 1;
  57.     else sign = -1;
  58.     int signa, signb;
  59.     if (A < 0) signa = -1;
  60.     else signa = 1;
  61.     if (B < 0) signb = -1;
  62.     else signb = 1;
  63.     int f = 0;
  64.  
  65.     paint_pixel(image, x0, y0, width_pixel, Red, Green, Blue);
  66.     draw_Circle(image, x0, y0, line_fat, width_pixel, Red, Green, Blue);
  67.     int x = x0, y = y0;
  68.     if (sign == -1) {
  69.         do {
  70.             f += A * signa;
  71.             if (f > 0) {
  72.                 f -= B * signb;
  73.                 y += signa;
  74.             }
  75.             x -= signb;
  76.             paint_pixel(image, x, y, width_pixel, Red, Green, Blue);
  77.             draw_Circle(image, x, y, line_fat, width_pixel, Red, Green, Blue);
  78.         } while (x != x1 || y != y1);
  79.     } else {
  80.         do {
  81.             f += B * signb;
  82.             if (f > 0) {
  83.                 f -= A * signa;
  84.                 x -= signb;
  85.             }
  86.             y += signa;
  87.             paint_pixel(image, x, y, width_pixel, Red, Green, Blue);
  88.             draw_Circle(image, x, y, line_fat, width_pixel, Red, Green, Blue);
  89.         } while (x != x1 || y != y1);
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement