home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / circle_c / b-circle.c next >
Text File  |  1994-11-17  |  868b  |  55 lines

  1. /*
  2.  
  3. Bresenham's circle drawing algorithm
  4.  
  5.  
  6. Coded by James Holub, aka Copperhead, of Omega
  7.  
  8. This routine is completely freeware, you may use it in
  9. anything you want, no credits needed...
  10.  
  11. */
  12.  
  13.  
  14.  
  15. void circle(int x, int y, unsigned int r, int color)
  16. {
  17.  
  18. int xs, ys;
  19. int da, db, s;
  20.  
  21. xs = 0;
  22. ys = r;
  23.  
  24. do {
  25.  
  26. /*
  27.  
  28. Your pixel-plotting routine goes here. The following example
  29. functions show what the calculations are
  30.  
  31. my_plot(x+xs, y-ys, color);
  32. my_plot(x+xs, y+ys, color);
  33. my_plot(x-xs, y-ys, color);
  34. my_plot(x-xs, y+ys, color);
  35. my_plot(x+ys, y-xs, color);
  36. my_plot(x+ys, y+xs, color);
  37. my_plot(x-ys, y-xs, color);
  38. my_plot(x-ys, y+xs, color);
  39.  
  40. */
  41.  
  42. da = ((xs + 1) * (xs + 1)) + (ys * ys) - (r * r);
  43. db = ((xs + 1) * (xs + 1)) + ((ys - 1) * (ys - 1)) - (r * r);
  44. s  = da + db;
  45. xs++;
  46.  
  47. if (s > 0)
  48.     ys--;
  49.  
  50.     } while (xs <= ys);
  51.  
  52.  
  53. }
  54.  
  55.