home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / touchup / part06 / oval.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-14  |  4.2 KB  |  125 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.     file: oval.c
  26.     purpose: this file contain the functions that draw ovals
  27.  
  28.     modifications:
  29.         date:    Tue Mar 22 22:04:58 EST 1988
  30.         author:    rayk
  31.         changes:add comments
  32. **************************************************************************/
  33.  
  34. #include"header.h"
  35.  
  36.  
  37. /*
  38.  * draw an oval by making the sides by vectors and ends by semicircles
  39.  */
  40.      draw_oval(pw, center_x,center_y, curr_pos_x,curr_pos_y,flag)
  41.  
  42.        Pixwin            *pw;
  43.        int         center_x,center_y,curr_pos_x,curr_pos_y;
  44.        int                flag;
  45.    
  46.      {    
  47.        struct  pr_pos     center,
  48.                          curr_pos;
  49.         int             x, y, radius,
  50.             error, npts,
  51.                 h_width, h_height,
  52.             x_off, y_off,ROP;
  53.  
  54.     if (flag)
  55.      {
  56.       if (image_depth > 1)
  57.           ROP = PIX_SRC;
  58.       else
  59.         ROP = PIX_SET;
  60.      }
  61.         else
  62.        ROP = PIX_XOR;
  63.  
  64.     center.x = center_x;
  65.     center.y = center_y;
  66.     curr_pos.x = curr_pos_x;
  67.     curr_pos.y = curr_pos_y;
  68.  
  69.           h_width = abs(curr_pos.x - center.x);
  70.           h_height = abs(curr_pos.y - center.y);
  71.           radius = MIN(h_width, h_height);
  72.   
  73.          /*
  74.       * draw line section of oval
  75.           */
  76.           if (radius == h_height)
  77.            { x_off = h_width-radius;   y_off = 0;
  78.              pw_vector(pw, center.x-x_off, center.y+radius,
  79.                        center.x+x_off, center.y+radius, ROP, cur_color);
  80.              pw_vector(pw, center.x-x_off, center.y-radius,
  81.                        center.x+x_off, center.y-radius, ROP, cur_color);
  82.            }
  83.           else
  84.            { x_off = 0;   y_off = h_height-radius;
  85.              pw_vector(pw, center.x-radius, center.y-y_off,
  86.                        center.x-radius, center.y+y_off, ROP, cur_color);
  87.              pw_vector(pw, center.x+radius, center.y-y_off,
  88.                        center.x+radius, center.y+y_off, ROP, cur_color);
  89.            }
  90.        /*
  91.         * draw rounded corners of oval
  92.         */
  93.        x = 0;  y = radius; npts = 0;
  94.        error = 3 - (radius << 1);
  95.  
  96.          while (x < y)
  97.          {
  98.            ptlist[npts].x=center.x+(x+x_off); ptlist[npts++].y=center.y+(y+y_off);
  99.            ptlist[npts].x=center.x-(x+x_off); ptlist[npts++].y=center.y+(y+y_off);
  100.            ptlist[npts].x=center.x+(x+x_off); ptlist[npts++].y=center.y-(y+y_off);
  101.            ptlist[npts].x=center.x-(x+x_off); ptlist[npts++].y=center.y-(y+y_off);
  102.            ptlist[npts].x=center.x+(y+x_off); ptlist[npts++].y=center.y+(x+y_off);
  103.            ptlist[npts].x=center.x-(y+x_off); ptlist[npts++].y=center.y+(x+y_off);
  104.            ptlist[npts].x=center.x+(y+x_off); ptlist[npts++].y=center.y-(x+y_off);
  105.            ptlist[npts].x=center.x-(y+x_off); ptlist[npts++].y=center.y-(x+y_off);
  106.              
  107.            if (error < 0)
  108.               error = error + (x << 2) + 6;
  109.            else
  110.               error = error + ((x-y--) << 2) + 10;
  111.            x++;
  112.           }  /* end of while (x , y) */
  113.  
  114.           if (x == y)
  115.           {
  116.            ptlist[npts].x=center.x+(x+x_off); ptlist[npts++].y=center.y+(y+y_off);
  117.            ptlist[npts].x=center.x-(x+x_off); ptlist[npts++].y=center.y+(y+y_off);
  118.            ptlist[npts].x=center.x+(x+x_off); ptlist[npts++].y=center.y-(y+y_off);
  119.            ptlist[npts].x=center.x-(x+x_off); ptlist[npts++].y=center.y-(y+y_off);
  120.           }
  121.           if (flag)
  122.         my_pw_polypoint(pw,0,0,npts,ptlist,ROP);
  123. }  /* end of function draw_oval() */
  124.  
  125.