home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / touchup / part05 / circle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-14  |  3.5 KB  |  112 lines

  1.  
  2. /**************************************************************************
  3.    Touchup a bitmap graphics editor for the Sun Workstation running SunView
  4.    Copyright (c) 1988 by Raymond Kreisel
  5.    1/22/88 @ Suny Stony Brook
  6.  
  7.    This program may be redistributed without fee as long as this copyright
  8.    notice is intact.
  9.  
  10. ==> PLEASE send comments and bug reports to one of the following addresses:
  11.  
  12.        Ray Kreisel
  13.        CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  14.  
  15.        UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  16.        ARPA-Internet: rayk@sbcs.sunysb.edu            
  17.        CSnet: rayk@suny-sb
  18.        (If nobody is home at any of the above addresses try:
  19.         S72QKRE@TOWSONVX.BITNET                    )
  20.  
  21.  "If I get home before daylight, I just might get some sleep tonight...."
  22.  
  23. **************************************************************************/
  24.  
  25. /**************************************************************************
  26.     file: circle.c
  27.     purpose: This file contains that routines that draw circles
  28.         on the screen. A UNDOCUMENTED Sunview function "pw_polypoint"
  29.         is used to get the list of points that make the circle
  30.         on to the screen AMAZINGLY FAST.
  31.         The points that make up the circle are calculated with
  32.         bresenhams (sp?) incremental circle algorithm.
  33.  
  34.     modifications:
  35.         date:    Tue Mar 22 22:04:58 EST 1988
  36.         author:    rayk
  37.         changes:add comments
  38. **************************************************************************/
  39.  
  40. #include "header.h"
  41.  
  42. struct  pr_pos  ptlist[MAX_PTS];
  43.  
  44. draw_circle(pw, center_x,center_y, radius,ROP)
  45. int        center_x,center_y;
  46. Pixwin            *pw;
  47. int                radius,ROP;
  48. {
  49. struct pr_pos      center;
  50.  
  51.         int             x,y,
  52.                         error, numpts;
  53.  
  54.     if (radius==0) return(0);
  55.     center.x = center_x;
  56.     center.y = center_y;
  57.  
  58.            x = 0; y = radius; numpts = 0;
  59.            error = 3 - (radius << 1);
  60.  
  61.            while (x < y)
  62.            {
  63.              ptlist[numpts].x=center.x+x;   ptlist[numpts++].y=center.y+y;
  64.              ptlist[numpts].x=center.x-x;   ptlist[numpts++].y=center.y+y;
  65.              ptlist[numpts].x=center.x+x;   ptlist[numpts++].y=center.y-y;
  66.              ptlist[numpts].x=center.x-x;   ptlist[numpts++].y=center.y-y;
  67.              ptlist[numpts].x=center.x+y;   ptlist[numpts++].y=center.y+x;
  68.              ptlist[numpts].x=center.x-y;   ptlist[numpts++].y=center.y+x;
  69.              ptlist[numpts].x=center.x+y;   ptlist[numpts++].y=center.y-x;
  70.              ptlist[numpts].x=center.x-y;   ptlist[numpts++].y=center.y-x;
  71.    
  72.              if (error < 0)
  73.                 error = error + (x << 2) + 6;
  74.              else
  75.                 error = error + ((x-y--) << 2) + 10;
  76.              x++;
  77.            }  /* end of while (x , y) */
  78.    
  79.            if (x == y)
  80.            {
  81.              ptlist[numpts].x=center.x+x;   ptlist[numpts++].y=center.y+y;
  82.              ptlist[numpts].x=center.x-x;   ptlist[numpts++].y=center.y+y;
  83.              ptlist[numpts].x=center.x+x;   ptlist[numpts++].y=center.y-y;
  84.              ptlist[numpts].x=center.x-x;   ptlist[numpts++].y=center.y-y;
  85.            }
  86.  
  87.        my_pw_polypoint(pw,0,0,numpts,ptlist,PIX_SET);
  88. }  /* end of function draw_circle() */   
  89.  
  90.  
  91.  
  92. my_pw_polypoint(temp_pw,off_x,off_y,count_pts,ptlist, ROP)
  93. Pixwin *temp_pw;
  94. int off_x,off_y,count_pts;
  95. struct pr_pos ptlist[];
  96. int ROP;
  97. {
  98.  
  99.   if (image_depth > 1)
  100.   {
  101.     while(--count_pts > 0)
  102.     {
  103.       pw_rop(temp_pw,off_x+ptlist[count_pts].x,off_y+ptlist[count_pts].y,1,1
  104.       ,PIX_COLOR(cur_color) | PIX_SRC ,pattern[0],0,0);
  105.     }
  106.   }
  107.   else
  108.   {
  109.     pw_polypoint(temp_pw,off_x,off_y,count_pts,ptlist,ROP);
  110.   }
  111. }
  112.