home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / gd201.zip / gd-2.0.1 / arc < prev    next >
Text File  |  2001-04-03  |  967b  |  32 lines

  1. /* s and e are integers modulo 360 (degrees), with 0 degrees
  2.   being the rightmost extreme and degrees changing clockwise.
  3.   cx and cy are the center in pixels; w and h are the horizontal 
  4.   and vertical diameter in pixels. Nice interface, but slow, since
  5.   I don't yet use Bresenham (I'm using an inefficient but
  6.   simple solution with too much work going on in it; generalizing
  7.   Bresenham to ellipses and partial arcs of ellipses is non-trivial,
  8.   at least for me) and there are other inefficiencies (small circles
  9.   do far too much work). */
  10.  
  11. void gdImageArc(gdImagePtr im, int cx, int cy, int w, int h, int s, int e, int color)
  12. {
  13.     int i;
  14.     int lx = 0, ly = 0;
  15.     int w2, h2;
  16.     w2 = w/2;
  17.     h2 = h/2;
  18.     while (e < s) {
  19.         e += 360;
  20.     }
  21.     for (i=s; (i <= e); i++) {
  22.         int x, y;
  23.         x = ((long)gdCosT[i % 360] * (long)w2 / 1024) + cx; 
  24.         y = ((long)gdSinT[i % 360] * (long)h2 / 1024) + cy;
  25.         if (i != s) {
  26.             gdImageLine(im, lx, ly, x, y, color);    
  27.         }
  28.         lx = x;
  29.         ly = y;
  30.     }
  31. }
  32.