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_triangles.c < prev    next >
C/C++ Source or Header  |  1989-12-12  |  7KB  |  386 lines

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