Advertisement
QwarkDev

DrawCircle | C++ | Windows

Nov 22nd, 2020 (edited)
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. /*
  2.     Функция позволяющая отрисовать круг (окружность) поверх всех окон (OS Windows)
  3.     Автор - aws_qwark (вдохновлено geniusenstein (ded))
  4. */
  5.  
  6. #include <Windows.h>
  7.  
  8. ...
  9.  
  10. void DrawCircle(
  11.     HDC      dc,                // Контекст отрисовки
  12.     POINT    position,          // Координаты центра
  13.     int      radius,            // Радиус круга (окружности)
  14.     COLORREF color,             // Цвет круга (окружности)
  15.     bool     isFilled = false,  // Будет ли фигура закрашенной
  16.     int      lineHeight = 20    // Если фигура не будет являться закрашенной, то этот параметр будет отвечать за толщину линии
  17. )
  18. {
  19.     int x = position.x - radius;
  20.     int y = position.y - radius;
  21.  
  22.     for (;;)
  23.     {
  24.         x++;
  25.  
  26.         if (x > position.x + radius)
  27.         {
  28.             x = position.x - radius;
  29.             y++;
  30.         }
  31.  
  32.         if (y > position.y + radius)
  33.         {
  34.             break;
  35.         }
  36.  
  37.         // Рисовать ли пиксель на текущих координатах?
  38.         bool predicate = false;
  39.  
  40.         if (isFilled) predicate = pow(x - position.x, 2) + pow(y - position.y, 2) <= radius * raduis;
  41.         else {
  42.             predicate = (x - position.x) * (x - position.x) + (y - position.y) * (y - position.y) <= radius * radius + lineHeight &&
  43.                         (x - position.x) * (x - position.x) + (y - position.y) * (y - position.y) >= radius * radius - lineHeight;
  44.         }
  45.  
  46.         // Если рисовать, то рисуем...
  47.         if (predicate) SetPixel(dc,  x, y, color);
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement