Advertisement
the_usik

circle_draw_using_decard

Nov 26th, 2021
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <graphics.h>
  2. #include <math.h>
  3. void safe_putpixel(int x, int y, int color) {
  4. putpixel(
  5. x < 0 ? 0 : x,
  6. y < 0 ? 0 : y,
  7. color);
  8. }
  9. void draw_circle(int x, int y, int radius) {
  10. int diameter = radius * 2;
  11. for (int i = 0; i < diameter; i++) {
  12. int xshift = sqrt(pow(radius, 2) - pow(i, 2));
  13. for (int j = 0; j < xshift; j++) {
  14. safe_putpixel(x + j, y - i, GREEN);
  15. safe_putpixel(x + j, y + i, GREEN);
  16. safe_putpixel(x + j - xshift, y - i, GREEN);
  17. safe_putpixel(x + j - xshift, y + i, GREEN);
  18. }
  19. }
  20. }
  21. int main() {
  22. int graphics_driver = DETECT;
  23. int gmode;
  24. initgraph(&graphics_driver, &gmode, "");
  25. draw_circle(0, 50, 10);
  26.  
  27. getch();
  28. closegraph();
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement