home *** CD-ROM | disk | FTP | other *** search
/ Monster Disc 2: The Best of 1992 / MONSTER2.ISO / prog / djgpp / cbgrx102.a01 / CONTRIB / LIBGRX / SRC / GENELLIP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-12  |  3.8 KB  |  94 lines

  1. /**
  2.  ** GENELLIP.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "grx.h"
  25. #include "libgrx.h"
  26.  
  27. #define TABLEN  256
  28.  
  29. static unsigned int sintab[] = {
  30.     0,   101,   201,   302,      402,     503,    603,   704,
  31.       804,   904,  1005,  1105,  1205,  1306,  1406,  1506,
  32.      1606,  1706,  1806,  1906,  2006,  2105,  2205,  2305,
  33.      2404,  2503,  2603,  2702,  2801,  2900,  2999,  3098,
  34.      3196,  3295,  3393,  3492,  3590,  3688,  3786,  3883,
  35.      3981,  4078,  4176,  4273,  4370,  4467,  4563,  4660,
  36.      4756,  4852,  4948,  5044,  5139,  5235,  5330,  5425,
  37.      5520,  5614,  5708,  5803,  5897,  5990,  6084,  6177,
  38.      6270,  6363,  6455,  6547,  6639,  6731,  6823,  6914,
  39.      7005,  7096,  7186,  7276,  7366,  7456,  7545,  7635,
  40.      7723,  7812,  7900,  7988,  8076,  8163,  8250,  8337,
  41.      8423,  8509,  8595,  8680,  8765,  8850,  8935,  9019,
  42.      9102,  9186,  9269,  9352,  9434,  9516,  9598,  9679,
  43.      9760,  9841,  9921, 10001, 10080, 10159, 10238, 10316,
  44.     10394, 10471, 10549, 10625, 10702, 10778, 10853, 10928,
  45.     11003, 11077, 11151, 11224, 11297, 11370, 11442, 11514,
  46.     11585, 11656, 11727, 11797, 11866, 11935, 12004, 12072,
  47.     12140, 12207, 12274, 12340, 12406, 12472, 12537, 12601,
  48.     12665, 12729, 12792, 12854, 12916, 12978, 13039, 13100,
  49.     13160, 13219, 13279, 13337, 13395, 13453, 13510, 13567,
  50.     13623, 13678, 13733, 13788, 13842, 13896, 13949, 14001,
  51.     14053, 14104, 14155, 14206, 14256, 14305, 14354, 14402,
  52.     14449, 14497, 14543, 14589, 14635, 14680, 14724, 14768,
  53.     14811, 14854, 14896, 14937, 14978, 15019, 15059, 15098,
  54.     15137, 15175, 15213, 15250, 15286, 15322, 15357, 15392,
  55.     15426, 15460, 15493, 15525, 15557, 15588, 15619, 15649,
  56.     15679, 15707, 15736, 15763, 15791, 15817, 15843, 15868,
  57.     15893, 15917, 15941, 15964, 15986, 16008, 16029, 16049,
  58.     16069, 16088, 16107, 16125, 16143, 16160, 16176, 16192,
  59.     16207, 16221, 16235, 16248, 16261, 16273, 16284, 16295,
  60.     16305, 16315, 16324, 16332, 16340, 16347, 16353, 16359,
  61.     16364, 16369, 16373, 16376, 16379, 16381, 16383, 16384,
  62.     16384
  63. };
  64.  
  65. int _GrGenerateEllipse(int pt[][2],int cx,int cy,int rx,int ry)
  66. {
  67. #define ulong    unsigned long
  68.     int nn,n2,n4;
  69.     int ii,dx,dy;
  70.     int gap,theta;
  71.  
  72.     n2 = rx + ry;
  73.     if(n2 > 128) n2 >>= 1;
  74.     for(nn = 32; nn < n2; nn <<= 1);
  75.     if(n2 > MAX_ELLIPSE_PTS) nn = MAX_ELLIPSE_PTS;
  76.     n2 = nn >> 1;
  77.     n4 = n2 >> 1;
  78.     gap = TABLEN / n4;
  79.     for(ii = theta = 0; ii <= n4; ii++,theta += gap) {
  80.         dx = (int)((((ulong)rx * (ulong)sintab[TABLEN - theta]) + 8192UL) >> 14);
  81.         dy = (int)((((ulong)ry * (ulong)sintab[theta]) + 8192UL) >> 14);
  82.         pt[ii][0]     = cx + dx;
  83.         pt[ii][1]     = cy - dy;
  84.         pt[n2-ii][0] = cx - dx;
  85.         pt[n2-ii][1] = cy - dy;
  86.         pt[n2+ii][0] = cx - dx;
  87.         pt[n2+ii][1] = cy + dy;
  88.         pt[nn-ii][0] = cx + dx;
  89.         pt[nn-ii][1] = cy + dy;
  90.     }
  91.     return(nn);
  92. }
  93.  
  94.