home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / x / x11p-13.zip / RCS / do_complex.c,v < prev    next >
Text File  |  1989-12-07  |  7KB  |  364 lines

  1. head     2.4;
  2. access   ;
  3. symbols  pre-merge:2.0;
  4. locks    ; strict;
  5. comment  @ * @;
  6.  
  7.  
  8. 2.4
  9. date     89.12.07.16.33.50;  author joel;  state Exp;
  10. branches ;
  11. next     2.3;
  12.  
  13. 2.3
  14. date     89.11.20.13.26.00;  author joel;  state Exp;
  15. branches ;
  16. next     2.2;
  17.  
  18. 2.2
  19. date     89.05.11.16.44.06;  author joel;  state Exp;
  20. branches ;
  21. next     2.1;
  22.  
  23. 2.1
  24. date     89.05.03.14.17.22;  author joel;  state Exp;
  25. branches ;
  26. next     2.0;
  27.  
  28. 2.0
  29. date     89.01.31.17.02.37;  author erik;  state Exp;
  30. branches ;
  31. next     1.2;
  32.  
  33. 1.2
  34. date     89.01.31.17.02.37;  author joel;  state Exp;
  35. branches ;
  36. next     1.1;
  37.  
  38. 1.1
  39. date     88.09.20.12.29.17;  author walker;  state Exp;
  40. branches ;
  41. next     ;
  42.  
  43.  
  44. desc
  45. @fill complex polygons
  46. @
  47.  
  48.  
  49. 2.4
  50. log
  51. @Changed interface to p->reps
  52. @
  53. text
  54. @/*****************************************************************************
  55. Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
  56.  
  57.                         All Rights Reserved
  58.  
  59. Permission to use, copy, modify, and distribute this software and its 
  60. documentation for any purpose and without fee is hereby granted, 
  61. provided that the above copyright notice appear in all copies and that
  62. both that copyright notice and this permission notice appear in 
  63. supporting documentation, and that the name of Digital not be
  64. used in advertising or publicity pertaining to distribution of the
  65. software without specific, written prior permission.  
  66.  
  67. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  68. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  69. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  70. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  71. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  72. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  73. SOFTWARE.
  74.  
  75. ******************************************************************************/
  76.  
  77. #include "x11perf.h"
  78.  
  79. #define NUM_POINTS 4    /* 4 points to an arrowhead */
  80. #define NUM_ANGLES 3    /* But mostly it looks like a triangle */
  81. static XPoint   *points;
  82. static GC       pgc;
  83.  
  84. extern double sin();
  85. extern double cos();
  86. extern double sqrt();
  87. #define PI  3.14159265357989
  88.  
  89. int InitComplexPoly(xp, p, reps)
  90.     XParms  xp;
  91.     Parms   p;
  92.     int     reps;
  93. {
  94.     int     i, j, numPoints;
  95.     int     x, y;
  96.     int     size, iradius;
  97.     double  phi, radius, delta, phi2;
  98.     XPoint  *curPoint;
  99.  
  100.     pgc = xp->fggc;
  101.  
  102.     size = p->special;
  103.     phi = 0.0;
  104.     radius = ((double) size) * sqrt(3.0)/2.0;
  105.     iradius = (int) radius + 1;
  106.     delta = 2.0 * PI / ((double) NUM_ANGLES);
  107.  
  108.     numPoints = (p->objects) * NUM_POINTS;  
  109.     points = (XPoint *)malloc(numPoints * sizeof(XPoint));
  110.     curPoint = points;
  111.     x = iradius;
  112.     y = iradius;
  113.     for (i = 0; i != p->objects; i++) {
  114.     for (j = 0; j != NUM_ANGLES; j++) {
  115.         phi2 = phi + ((double) j) * delta;
  116.         curPoint->x = (int) ((double)x + (radius * cos(phi2)) + 0.5);
  117.         curPoint->y = (int) ((double)y + (radius * sin(phi2)) + 0.5);
  118.         curPoint++;
  119.     }
  120.     curPoint->x = x;
  121.     curPoint->y = y;
  122.     curPoint++;
  123.  
  124.     phi += delta/10.0;
  125.     y += 2 * iradius;
  126.     if (y + iradius >= HEIGHT) {
  127.         y = iradius;
  128.         x += 2 * iradius;
  129.         if (x + iradius >= WIDTH) {
  130.         x = iradius;
  131.         }
  132.     }
  133.     }
  134.     return reps;
  135. }
  136.  
  137. void DoComplexPoly(xp, p, reps)
  138.     XParms  xp;
  139.     Parms   p;
  140.     int     reps;
  141. {
  142.     int     i, j;
  143.     XPoint  *curPoint;
  144.  
  145.     for (i = 0; i != reps; i++) {
  146.         curPoint = points;
  147.         for (j = 0; j != p->objects; j++) {
  148.             XFillPolygon(xp->d, xp->w, pgc, curPoint, NUM_POINTS, Complex, 
  149.              CoordModeOrigin);
  150.             curPoint += NUM_POINTS;
  151.       }
  152.         if (pgc == xp->bggc)
  153.             pgc = xp->fggc;
  154.         else
  155.             pgc = xp->bggc;
  156.     }
  157. }
  158.  
  159. void EndComplexPoly(xp, p)
  160.     XParms  xp;
  161.     Parms   p;
  162. {
  163.     free(points);
  164. }
  165.  
  166. @
  167.  
  168.  
  169. 2.3
  170. log
  171. @Declare pgc as static, so switch between fggc and bggc happens every time,
  172. not just within one iteration of tests.  (Helps make things look better on
  173. slow machines, which may only run 1 iteration.)
  174. @
  175. text
  176. @d36 1
  177. a36 1
  178. Bool InitComplexPoly(xp, p)
  179. d39 1
  180. d81 1
  181. a81 1
  182.     return True;
  183. d84 1
  184. a84 1
  185. void DoComplexPoly(xp, p)
  186. d87 1
  187. d92 1
  188. a92 1
  189.     for (i = 0; i != p->reps; i++) {
  190. @
  191.  
  192.  
  193. 2.2
  194. log
  195. @Parameters to all routines now (xp, p)
  196. MAXROWS used in all routines
  197. Junked most global communication variables
  198. @
  199. text
  200. @d28 2
  201. a29 1
  202. static XPoint *points;
  203. d46 2
  204. a86 1
  205.     GC      pgc;
  206. a89 1
  207.     pgc = xp->fggc;
  208. @
  209.  
  210.  
  211. 2.1
  212. log
  213. @Massive changes, I'm not going to go into details.
  214. @
  215. text
  216. @d1 23
  217. a28 2
  218. static GC bggc, fggc;
  219. static Window w;
  220. d35 3
  221. a37 3
  222. Bool InitComplexPoly(d, p)
  223.     Display *d;
  224.     Parms p;
  225. d39 5
  226. a43 5
  227.     int i, j, numPoints;
  228.     int x, y;
  229.     int size, iradius;
  230.     double phi, radius, delta, phi2;
  231.     XPoint *curPoint;
  232. d56 2
  233. a57 2
  234.     for (i = 0; i < p->objects; i++) {
  235.     for (j = 0; j < NUM_ANGLES; j++) {
  236. a76 1
  237.     CreatePerfStuff(d, 1, WIDTH, HEIGHT, &w, &bggc, &fggc);
  238. d80 3
  239. a82 3
  240. void DoComplexPoly(d, p)
  241.     Display *d;
  242.     Parms p;
  243. d84 3
  244. a86 3
  245.     GC pgc;
  246.     int i, j;
  247.     XPoint *curPoint;
  248. d88 2
  249. a89 3
  250.     pgc = bggc;
  251.     for (i=0; i<p->reps; i++)
  252.     {
  253. d91 2
  254. a92 2
  255.         for (j=0; j < p->objects; j++) {
  256.             XFillPolygon(d, w, pgc, curPoint, NUM_POINTS, Complex, 
  257. d96 2
  258. a97 2
  259.         if (pgc == bggc)
  260.             pgc = fggc;
  261. d99 1
  262. a99 1
  263.             pgc = bggc;
  264. d103 3
  265. a105 3
  266. void EndComplexPoly(d, p)
  267.     Display *d;
  268.     Parms p;
  269. a106 3
  270.     XDestroyWindow(d, w);
  271.     XFreeGC(d, bggc);
  272.     XFreeGC(d, fggc);
  273. @
  274.  
  275.  
  276. 2.0
  277. log
  278. @version from /usr/src/pmax
  279. @
  280. text
  281. @d3 2
  282. a4 1
  283. #define NUM_POINTS 5  /* 5 random points for the complex polygon */
  284. d7 1
  285. a7 6
  286. static Window w[4];
  287. static XRectangle ws[3] = {
  288.     {100, 100, 200, 200},
  289.     {150, 150, 200, 200},
  290.     {200, 200, 200, 200}
  291.   };
  292. d9 6
  293. a14 1
  294. void InitComplexPoly(d, p)
  295. d18 5
  296. a22 1
  297.     int i, numPoints, j, temp1;
  298. d24 7
  299. a30 3
  300.     for (i = 0; i < 4; i++)
  301.     w[i] = None;
  302.     numPoints = (p->objects) * NUM_POINTS;
  303. d32 23
  304. a54 6
  305.     i = 0;
  306.     /* for complex we are just using 4 random points */
  307.     for (j = 0; j < numPoints; j++)
  308.     {    
  309.         points[j].x = rand() % WIDTH;
  310.         points[j].y = rand() % HEIGHT;
  311. d56 2
  312. a57 5
  313.     CreatePerfStuff(d, 1, WIDTH, HEIGHT, w, &bggc, &fggc);
  314.     for (i = 0; i < p->special; i++)
  315.     w[i+1] = CreatePerfWindow(
  316.         d, ws[i].x, ws[i].y, ws[i].width, ws[i].height);
  317.     
  318. d73 1
  319. a73 1
  320.             XFillPolygon(d, w[0], pgc, curPoint, NUM_POINTS, Complex, 
  321. d88 1
  322. a88 4
  323.     int i;
  324.     for (i = 0; i < 4; i++)
  325.     if (w[i] != None)
  326.         XDestroyWindow(d, w[i]);
  327. @
  328.  
  329.  
  330. 1.2
  331. log
  332. @Added -fg -bg capabilities
  333. @
  334. text
  335. @@
  336.  
  337.  
  338. 1.1
  339. log
  340. @Initial revision
  341. @
  342. text
  343. @d5 1
  344. a5 1
  345. static GC whitegc, blackgc;
  346. d30 1
  347. a30 1
  348.     CreatePerfStuff(d, 1, WIDTH, HEIGHT, w, &whitegc, &blackgc);
  349. d45 1
  350. a45 1
  351.     pgc = whitegc;
  352. d54 2
  353. a55 2
  354.         if (pgc == whitegc)
  355.             pgc = blackgc;
  356. d57 1
  357. a57 1
  358.             pgc = whitegc;
  359. d69 2
  360. a70 2
  361.     XFreeGC(d, whitegc);
  362.     XFreeGC(d, blackgc);
  363. @
  364.