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 / do_complex.c < prev    next >
C/C++ Source or Header  |  1991-05-02  |  4KB  |  127 lines

  1. /*****************************************************************************
  2. Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
  3.  
  4.                         All Rights Reserved
  5.  
  6. Permission to use, copy, modify, and distribute this software and its 
  7. documentation for any purpose and without fee is hereby granted, 
  8. provided that the above copyright notice appear in all copies and that
  9. both that copyright notice and this permission notice appear in 
  10. supporting documentation, and that the name of Digital not be
  11. used in advertising or publicity pertaining to distribution of the
  12. software without specific, written prior permission.  
  13.  
  14. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20. SOFTWARE.
  21.  
  22. ******************************************************************************/
  23.  
  24. #include "x11perf.h"
  25.  
  26. #define NUM_POINTS 4    /* 4 points to an arrowhead */
  27. #define NUM_ANGLES 3    /* But mostly it looks like a triangle */
  28. static XPoint   *points;
  29. static GC       pgc;
  30.  
  31. extern double sin();
  32. extern double cos();
  33. extern double sqrt();
  34. #define PI  3.14159265357989
  35.  
  36. int InitComplexPoly(xp, p, reps)
  37.     XParms  xp;
  38.     Parms   p;
  39.     int     reps;
  40. {
  41.     int     i, j, numPoints;
  42.     int     x, y;
  43.     int     size, iradius;
  44.     double  phi, phiinc, radius, delta, phi2;
  45.     XPoint  *curPoint;
  46.  
  47.     pgc = xp->fggc;
  48.  
  49.     size = p->special;
  50.     phi = 0.0;
  51.     delta = 2.0 * PI / ((double) NUM_ANGLES);
  52.     if (xp->version == VERSION1_2) {
  53.     radius = ((double) size) * sqrt(3.0)/2.0;
  54.     phiinc = delta/10.0;
  55.     } else {
  56.     /* Version 1.2's radius computation was completely bogus, and resulted
  57.        in triangles with sides about 50% longer than advertised.  Since
  58.        in version 1.3 triangles are scaled to cover size^2 pixels, we do
  59.        the same computation here.  The arrowheads are a little larger than
  60.        simple triangles, because they lose 1/3 of their area due to the
  61.        notch cut out from them, so radius has to be sqrt(3/2) larger than
  62.        for simple triangles.
  63.      */
  64.     radius = ((double) size) * sqrt(sqrt(4.0/3.0));
  65.     phiinc = 1.75*PI / ((double) p->objects);
  66.     }
  67.     iradius = (int) radius + 1;
  68.  
  69.     numPoints = (p->objects) * NUM_POINTS;  
  70.     points = (XPoint *)malloc(numPoints * sizeof(XPoint));
  71.     curPoint = points;
  72.     x = iradius;
  73.     y = iradius;
  74.     for (i = 0; i != p->objects; i++) {
  75.     for (j = 0; j != NUM_ANGLES; j++) {
  76.         phi2 = phi + ((double) j) * delta;
  77.         curPoint->x = (int) ((double)x + (radius * cos(phi2)) + 0.5);
  78.         curPoint->y = (int) ((double)y + (radius * sin(phi2)) + 0.5);
  79.         curPoint++;
  80.     }
  81.     curPoint->x = x;
  82.     curPoint->y = y;
  83.     curPoint++;
  84.  
  85.     phi += phiinc;
  86.     y += 2 * iradius;
  87.     if (y + iradius >= HEIGHT) {
  88.         y = iradius;
  89.         x += 2 * iradius;
  90.         if (x + iradius >= WIDTH) {
  91.         x = iradius;
  92.         }
  93.     }
  94.     }
  95.     return reps;
  96. }
  97.  
  98. void DoComplexPoly(xp, p, reps)
  99.     XParms  xp;
  100.     Parms   p;
  101.     int     reps;
  102. {
  103.     int     i, j;
  104.     XPoint  *curPoint;
  105.  
  106.     for (i = 0; i != reps; i++) {
  107.         curPoint = points;
  108.         for (j = 0; j != p->objects; j++) {
  109.             XFillPolygon(xp->d, xp->w, pgc, curPoint, NUM_POINTS, Complex, 
  110.              CoordModeOrigin);
  111.             curPoint += NUM_POINTS;
  112.       }
  113.         if (pgc == xp->bggc)
  114.             pgc = xp->fggc;
  115.         else
  116.             pgc = xp->bggc;
  117.     }
  118. }
  119.  
  120. void EndComplexPoly(xp, p)
  121.     XParms  xp;
  122.     Parms   p;
  123. {
  124.     free(points);
  125. }
  126.  
  127.