home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource1 / ast40dos / xcharts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-18  |  38.3 KB  |  1,064 lines

  1. /*
  2. ** Astrolog (Version 4.00) File: xcharts.c
  3. **
  4. ** IMPORTANT NOTICE: the graphics database and chart display routines
  5. ** used in this program are Copyright (C) 1991-1993 by Walter D. Pullen
  6. ** (cruiser1@stein.u.washington.edu). Permission is granted to freely
  7. ** use and distribute these routines provided one doesn't sell,
  8. ** restrict, or profit from them in any way. Modification is allowed
  9. ** provided these notices remain with any altered or edited versions of
  10. ** the program.
  11. **
  12. ** The main planetary calculation routines used in this program have
  13. ** been Copyrighted and the core of this program is basically a
  14. ** conversion to C of the routines created by James Neely as listed in
  15. ** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
  16. ** available from Matrix Software. The copyright gives us permission to
  17. ** use the routines for personal use but not to sell them or profit from
  18. ** them in any way.
  19. **
  20. ** The PostScript code within the core graphics routines are programmed
  21. ** and Copyright (C) 1992-1993 by Brian D. Willoughby
  22. ** (brianw@sounds.wa.com). Conditions are identical to those above.
  23. **
  24. ** The extended accurate ephemeris databases and formulas are from the
  25. ** calculation routines in the program "Placalc" and are programmed and
  26. ** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
  27. ** (alois@azur.ch). The use of that source code is subject to
  28. ** regulations made by Astrodienst Zurich, and the code is not in the
  29. ** public domain. This copyright notice must not be changed or removed
  30. ** by any user of this program.
  31. **
  32. ** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
  33. ** X Window graphics initially programmed 10/23-29/1991.
  34. ** PostScript graphics initially programmed 11/29-30/1992.
  35. ** Last code change made 12/31/1993.
  36. */
  37.  
  38. #include "astrolog.h"
  39.  
  40. #ifdef GRAPH
  41.  
  42. /*
  43. ******************************************************************************
  44. ** Single Chart Graphics Subprograms.
  45. ******************************************************************************
  46. */
  47.  
  48. /* Given a string, draw it on the screen using the given color. The       */
  49. /* position of the text is based the saved positions of where we drew the */
  50. /* text the last time the routine was called, being either directly below */
  51. /* in the same column or in the same row just to the right. This is used  */
  52. /* by the sidebar drawing routine to print a list of text on the chart.   */
  53.  
  54. int DrawPrint(string, m, n)
  55. char *string;
  56. int m, n;
  57. {
  58.   static int x0, x, y;
  59.  
  60.   if (string == NULL) {    /* Null string means just initialize position. */
  61.     x0 = x = m; y = n;
  62.     return y;
  63.   }
  64.   if (y >= charty)    /* Don't draw if we've scrolled off the chart bottom. */
  65.     return y;
  66.   DrawColor(m);
  67.   DrawText(string, x, y, -1);
  68.  
  69.   /* If the second parameter is TRUE, we stay on the same line, otherwise */
  70.   /* when FALSE we go to the next line at the original column setting.    */
  71.  
  72.   if (n)
  73.     x += StringLen(string)*FONTX*scalet;
  74.   else {
  75.     x = x0;
  76.     n = y;
  77.     y += FONTY*scalet;
  78.   }
  79.   return y;
  80. }
  81.  
  82.  
  83. /* Print text showing the chart information and house and planet positions */
  84. /* of a chart in a "sidebar" to the right of the chart in question. This   */
  85. /* is always done for the -v and -w graphic wheel charts unless the -v0    */
  86. /* switch flag is also set, in which case none of the stuff here is done.  */
  87.  
  88. void DrawInfo()
  89. {
  90.   char string[STRING];
  91.   int elemode[4][3], elem[4], mo[3], tot, pos, abo, lef, lea, i, y, a, s;
  92.  
  93. #ifdef INTERPRET
  94.   /* Hack: Just for fun, if interpretation is active (which normally has  */
  95.   /* no effect whatsoever on graphics) we'll decorate the chart a little. */
  96.  
  97.   if (interpret) {
  98.     if (screenwidth & 1) {
  99.       /* If screenwidth value is odd, draw a moire pattern in each corner. */
  100.       abo = charty/(screenwidth/10);
  101.       lef = chartx/(screenwidth/10);
  102.       for (y = 0; y <= 1; y++)
  103.         for (i = 0; i <= 1; i++)
  104.           for (s = 0; s <= 1; s++)
  105.             for (a = 1; a < (s ? lef : abo)*2; a++) {
  106.               DrawColor(a & 1 ? gray : off);
  107.               DrawLine(i ? chartx-1-lef : lef, y ? charty-1-abo : abo,
  108.                 s ? (i ? chartx-1-a : a) : i*(chartx-1),
  109.                 s ? y*(charty-1) : (y ? charty-1-a : a));
  110.             }
  111.     } else {
  112.       /* If screenwidth is even, draw spider web lines in each corner. */
  113.       DrawColor(gray);
  114.       tot = screenwidth*3/20;
  115.       abo = charty/4;
  116.       lef = chartx/4;
  117.       for (y = 0; y <= 1; y++)
  118.         for (i = 0; i <= 1; i++)
  119.           for (a = 1; a < tot; a++)
  120.             DrawLine(i*(chartx-1), y ? (charty-1-a*abo/tot) : a*abo/tot,
  121.               i ? chartx-1-lef+a*lef/tot : lef-a*lef/tot, y*(charty-1));
  122.     }
  123.   }
  124. #endif
  125.   if (!xtext || (exdisplay & DASHv0) > 0)    /* Don't draw sidebar if */
  126.     return;                                  /* -v0 flag is set.      */
  127.  
  128.   a = ansi;
  129.   ansi = FALSE;
  130.   seconds = -seconds;
  131.   DrawColor(hilite);
  132.   if (xborder)
  133.     DrawLine(chartx-1, 0, chartx-1, charty-1);
  134.   chartx += SIDET;
  135.   DrawPrint(NULL, chartx-SIDET+FONTX*scalet, FONTY*7/5*scalet);
  136.  
  137.   /* Print chart header and setting information. */
  138.   sprintf(string, "%s %s", appname, VERSION);
  139.   DrawPrint(string, on, FALSE);
  140.   if (Mon == -1)
  141.     sprintf(string, "No time or space.");
  142.   else if (relation == DASHrc)
  143.     sprintf(string, "Composite chart.");
  144.   else {
  145.     sprintf(string, "%c%c%c %s", DAYNAM(DayOfWeek(Mon, Day, Yea)),
  146.       CharDate(Mon, Day, Yea, TRUE));
  147.     DrawPrint(string, hilite, FALSE);
  148.     DrawPrint(CharTime((int)floor(Tim), (int)(FRACT(dabs(Tim))*100.0)),
  149.       hilite, TRUE);
  150.     sprintf(string, " (%d:%02d GMT)", (int)(-Zon),
  151.       (int)(FRACT(dabs(Zon))*100.0+ROUND));
  152.   }
  153.   DrawPrint(string, hilite, FALSE);
  154.   DrawPrint(CharLocation(Lon, Lat, 100.0), hilite, FALSE);
  155.   sprintf(string, "%s houses.", systemname[housesystem]);
  156.   DrawPrint(string, hilite, FALSE);
  157.   sprintf(string, "%s zodiac.", operation & DASHs ? "Siderial" : "Tropical");
  158.   DrawPrint(string, hilite, FALSE);
  159.   sprintf(string, "Julian Day = %10.3f", JulianDayFromTime(T));
  160.   DrawPrint(string, hilite, FALSE);
  161.  
  162.   /* Print house cusp positions. */
  163.   DrawPrint("", hilite, FALSE);
  164.   for (i = 1; i <= SIGNS; i++) {
  165.     sprintf(string, "%2d%s house: ", i, post[i]);
  166.     y = DrawPrint(string, signcolor(i), TRUE);
  167.     if (!seconds && (scale == 100 || !xfont || !xfile) && y < charty) {
  168.       s = scale;
  169.       scale = 100*scalet;
  170.       DrawSign(i, chartx-12*scalet, y-(FONTY/2-1)*scalet);
  171.       scale = s;
  172.     }
  173.     DrawPrint(CharZodiac(house[i]), signcolor(ZTOS(house[i])), FALSE);
  174.   }
  175.  
  176.   /* Print planet positions. */
  177.   DrawPrint("", hilite, FALSE);
  178.   for (i = 1; i <= total; i++) if (!ignore[i]) {
  179.     sprintf(string, seconds ? "%3.3s: " : "%4.4s: ", objectname[i]);
  180.     DrawPrint(string, objectcolor[i], TRUE);
  181.     y = DrawPrint(CharZodiac(planet[i]), signcolor(ZTOS(planet[i])), TRUE);
  182.     if (!seconds && i < S_LO &&
  183.       (scale == 100 || !xfont || !xfile) && y < charty) {
  184.       s = scale;
  185.       scale = 100*scalet;
  186.       DrawObject(i, chartx-12*scalet, y-(FONTY/2-1)*scalet);
  187.       scale = s;
  188.     }
  189.     sprintf(string, "%c ", ret[i] < 0.0 ? 'R' : ' ');
  190.     DrawPrint(string, on, TRUE);
  191.     DrawPrint(CharAltitude(planetalt[i]), hilite, FALSE);
  192.   }
  193.  
  194.   /* Print element table information. */
  195.   DrawPrint("", hilite, FALSE);
  196.   CreateElemTable(elemode, elem, mo, &tot, &pos, &abo, &lef, &lea);
  197.   sprintf(string, "Fire: %d, Earth: %d,", elem[_FIR], elem[_EAR]);
  198.   DrawPrint(string, hilite, FALSE);
  199.   sprintf(string, "Air : %d, Water: %d", elem[_AIR], elem[_WAT]);
  200.   DrawPrint(string, hilite, FALSE);
  201.   sprintf(string, "Car: %d, Fix: %d, Mut: %d", mo[0], mo[1], mo[2]);
  202.   DrawPrint(string, hilite, FALSE);
  203.   sprintf(string, "Yang: %d, Yin: %d", pos, tot-pos);
  204.   DrawPrint(string, hilite, FALSE);
  205.   sprintf(string, "N: %d, S: %d, W: %d, E: %d", abo, tot-abo, tot-lef, lef); 
  206.   DrawPrint(string, hilite, FALSE);
  207.   seconds = -seconds;
  208.   ansi = a;
  209. }
  210.  
  211.  
  212. /* Draw a wheel chart, in which the 12 signs and houses are delineated, and  */
  213. /* the planets are inserted in their proper places. This is the default      */
  214. /* graphics chart to generate, as is done when the -v or -w (or no) switches */
  215. /* are included with -X. Draw the aspects in the middle of chart, too.       */
  216.  
  217. void XChartWheel()
  218. {
  219.   real xsign[SIGNS+1], xhouse[SIGNS+1], xplanet[TOTAL+1], symbol[TOTAL+1];
  220.   int cx, cy, i, j;
  221.   real asc, orb = DEFORB*256.0/(real)charty*(real)SCALE,
  222.     unitx, unity, px, py, temp;
  223.  
  224.   /* Set up variables and temporarily automatically decrease the horizontal */
  225.   /* chart size to leave room for the sidebar if that mode is in effect.    */
  226.  
  227.   if (xtext && !(exdisplay & DASHv0))
  228.     chartx -= SIDET;
  229.   cx = chartx/2 - 1; cy = charty/2 - 1;
  230.   unitx = (real)cx; unity = (real)cy;
  231.   asc = xeast ? planet[abs(xeast)]+90*(xeast < 0) : house[1];
  232.   InitCircle();
  233.  
  234.   /* Fill out arrays with the angular degree on the circle of where to    */
  235.   /* place each object, cusp, and sign glyph based on how the chart mode. */
  236.  
  237.   if (modex == MODEv) {
  238.     for (i = 1; i <= SIGNS; i++)
  239.       xhouse[i] = PZ(house[i]);
  240.   } else {
  241.     asc -= house[1];
  242.     for (i = 1; i <= SIGNS; i++)
  243.       xhouse[i] = PZ(STOZ(i));
  244.   }
  245.   for (i = 1; i <= SIGNS; i++)
  246.     xsign[i] = PZ(XHousePlaceIn(STOZ(i)));
  247.   for (i = 1; i <= total; i++)
  248.     xplanet[i] = PZ(XHousePlaceIn(planet[i]));
  249.  
  250.   /* Draw Ascendant/Descendant and Midheaven/Nadir lines across whole chart. */
  251.  
  252.   DrawColor(hilite);
  253.   DrawDash(cx+POINT(unitx, 0.99, PX(xhouse[1])),
  254.            cy+POINT(unity, 0.99, PY(xhouse[1])),
  255.            cx+POINT(unitx, 0.99, PX(xhouse[7])),
  256.            cy+POINT(unity, 0.99, PY(xhouse[7])), !xcolor);
  257.   DrawDash(cx+POINT(unitx, 0.99, PX(xhouse[10])),
  258.            cy+POINT(unity, 0.99, PY(xhouse[10])),
  259.            cx+POINT(unitx, 0.99, PX(xhouse[4])),
  260.            cy+POINT(unity, 0.99, PY(xhouse[4])), !xcolor);
  261.  
  262.   /* Draw small five or one degree increments around the zodiac sign ring. */
  263.  
  264.   for (i = 0; i < DEGR; i += 5-(xcolor || psfile || metafile)*4) {
  265.     temp = PZ(XHousePlaceIn((real)i));
  266.     px = PX(temp); py = PY(temp);
  267.     DrawColor(i%5 ? gray : on);
  268.     DrawDash(cx+POINT(unitx, 0.75, px), cy+POINT(unity, 0.75, py),
  269.       cx+POINT(unitx, 0.80, px), cy+POINT(unity, 0.80, py),
  270.       ((psfile || metafile) && i%5)*2);
  271.   }
  272.  
  273.   /* Draw circles for the zodiac sign and house rings. */
  274.  
  275.   DrawColor(on);
  276.   DrawCircle(cx, cy, (int)(unitx*0.95+ROUND), (int)(unity*0.95+ROUND));
  277.   DrawCircle(cx, cy, (int)(unitx*0.80+ROUND), (int)(unity*0.80+ROUND));
  278.   DrawCircle(cx, cy, (int)(unitx*0.75+ROUND), (int)(unity*0.75+ROUND));
  279.   DrawCircle(cx, cy, (int)(unitx*0.65+ROUND), (int)(unity*0.65+ROUND));
  280.  
  281.   /* Draw the glyphs for the signs and houses themselves. */
  282.  
  283.   for (i = 1; i <= SIGNS; i++) {
  284.     temp = xsign[i];
  285.     DrawColor(on);
  286.     DrawLine(cx+POINT(unitx, 0.95, PX(temp)),      /* Draw lines separating */
  287.       cy+POINT(unity, 0.95, PY(temp)),             /* each sign and house   */
  288.       cx+POINT(unitx, 0.80, PX(temp)),             /* from each other.      */
  289.       cy+POINT(unity, 0.80, PY(temp)));
  290.     DrawLine(cx+POINT(unitx, 0.75, PX(xhouse[i])),
  291.       cy+POINT(unity, 0.75, PY(xhouse[i])),
  292.       cx+POINT(unitx, 0.65, PX(xhouse[i])),
  293.       cy+POINT(unity, 0.65, PY(xhouse[i])));
  294.     if (xcolor && i%3 != 1) {                                 /* Lines from */
  295.       DrawColor(gray);                                        /* each house */
  296.       DrawDash(cx, cy, cx+POINT(unitx, 0.65, PX(xhouse[i])),  /* to center  */
  297.         cy+POINT(unity, 0.65, PY(xhouse[i])), 1);             /* of wheel.  */
  298.     }
  299.     temp = Midpoint(temp, xsign[Mod12(i+1)]);
  300.     DrawColor(signcolor(i));
  301.     DrawSign(i, cx+POINT(unitx, 0.875, PX(temp)),
  302.       cy+POINT(unity, 0.875, PY(temp)));
  303.     temp = Midpoint(xhouse[i], xhouse[Mod12(i+1)]);
  304.     DrawHouse(i, cx+POINT(unitx, 0.70, PX(temp)),
  305.       cy+POINT(unity, 0.70, PY(temp)));
  306.   }
  307.   for (i = 1; i <= total; i++)    /* Figure out where to put planet glyphs. */
  308.     symbol[i] = xplanet[i];
  309.   FillSymbolRing(symbol);
  310.  
  311.   /* For each planet, draw a small dot indicating where it is, and then */
  312.   /* a line from that point to the planet's glyph.                      */
  313.  
  314.   for (i = 1; i <= total; i++) if (Proper(i)) {
  315.     if (xlabel) {
  316.       temp = symbol[i];
  317.       DrawColor(ret[i] < 0.0 ? gray : on);
  318.       DrawDash(cx+POINT(unitx, 0.52, PX(xplanet[i])),
  319.         cy+POINT(unity, 0.52, PY(xplanet[i])),
  320.         cx+POINT(unitx, 0.56, PX(temp)),
  321.         cy+POINT(unity, 0.56, PY(temp)),
  322.         (ret[i] < 0.0 ? 1 : 0) - xcolor);
  323.       DrawObject(i, cx+POINT(unitx, 0.60, PX(temp)),
  324.         cy+POINT(unity, 0.60, PY(temp)));
  325.     } else
  326.       DrawColor(objectcolor[i]);
  327.     DrawPoint(cx+POINT(unitx, 0.50, PX(xplanet[i])),
  328.       cy+POINT(unity, 0.50, PY(xplanet[i])));
  329.   }
  330.  
  331.   /* Draw lines connecting planets which have aspects between them. */
  332.  
  333.   if (!xbonus) {          /* Don't draw aspects in bonus mode. */
  334.     CreateGrid(FALSE);
  335.     for (j = total; j >= 2; j--)
  336.       for (i = j-1; i >= 1; i--)
  337.         if (grid->n[i][j] && Proper(i) && Proper(j)) {
  338.           DrawColor(aspectcolor[grid->n[i][j]]);
  339.           DrawDash(cx+POINT(unitx, 0.48, PX(xplanet[i])),
  340.             cy+POINT(unity, 0.48, PY(xplanet[i])),
  341.             cx+POINT(unitx, 0.48, PX(xplanet[j])),
  342.             cy+POINT(unity, 0.48, PY(xplanet[j])),
  343.             abs(grid->v[i][j]/60/2));
  344.         }
  345.   }
  346.  
  347.   /* Go draw sidebar with chart information and positions if need be. */
  348.  
  349.   DrawInfo();
  350. }
  351.  
  352.  
  353. /* Draw an astro-graph chart on a map of the world, i.e. the draw the     */
  354. /* Ascendant, Descendant, Midheaven, and Nadir lines corresponding to the */
  355. /* time in the chart. This chart is done when the -L switch is combined   */
  356. /* with the -X switch.                                                    */
  357.  
  358. void XChartAstroGraph()
  359. {
  360.   real planet1[TOTAL+1], planet2[TOTAL+1],
  361.     end1[TOTAL*2+1], end2[TOTAL*2+1],
  362.     symbol1[TOTAL*2+1], symbol2[TOTAL*2+1],
  363.     lon = Lon, longm, x, y, z, ad, oa, am, od, dm, lat;
  364.   int unit = SCALE, stroke, lat1 = -60, lat2 = 75, y1, y2, xold1, xold2,
  365.     i, j, k, l;
  366.  
  367.   /* Erase top and bottom parts of map. We don't draw the astro-graph lines */
  368.   /* above certain latitudes, and this gives us room for glyph labels, too. */
  369.  
  370.   y1 = (91-lat1)*SCALE;
  371.   y2 = (91-lat2)*SCALE;
  372.   DrawColor(off);
  373.   DrawBlock(1, 1, chartx-2, y2-1);
  374.   DrawBlock(1, charty-2, chartx-2, y1+1);
  375.   DrawColor(hilite);
  376.   DrawDash(0, charty/2, chartx-2, charty/2, 4);    /* Draw equator. */
  377.   DrawColor(on);
  378.   DrawLine(1, y2, chartx-2, y2);
  379.   DrawLine(1, y1, chartx-2, y1);
  380.   for (i = 1; i <= total*2; i++)
  381.     end1[i] = end2[i] = -LARGE;
  382.  
  383.   /* Draw small hatches every 5 degrees along edges of world map. */
  384.  
  385.   DrawColor(hilite);
  386.   for (i = lat1; i <= lat2; i += 5) {
  387.     j = (91-i)*SCALE;
  388.     k = (2+(i%10 == 0)+2*(i%30 == 0))*scalet;
  389.     DrawLine(1, j, k, j);
  390.     DrawLine(chartx-2, j, chartx-1-k, j);
  391.   }
  392.   for (i = -180; i < 180; i += 5) {
  393.     j = (180-i)*SCALE;
  394.     k = (2+(i%10 == 0)+2*(i%30 == 0)+(i%90 == 0))*scalet;
  395.     DrawLine(j, y2+1, j, y2+k);
  396.     DrawLine(j, y1-1, j, y1-k);
  397.   }
  398.  
  399. #ifdef MATRIX
  400.   /* Calculate zenith locations of each planet. */
  401.  
  402.   for (i = 1; i <= total; i++) {
  403.     planet1[i] = DTOR(planet[i]);
  404.     planet2[i] = DTOR(planetalt[i]);
  405.     EclToEqu(&planet1[i], &planet2[i]);
  406.   }
  407.  
  408.   /* Draw the Midheaven lines and zenith location markings. */
  409.  
  410.   if (lon < 0.0)
  411.     lon += DEGREES;
  412.   for (i = 1; i <= total; i++) if (Proper(i)) {
  413.     x = DTOR(MC)-planet1[i];
  414.     if (x < 0.0)
  415.       x += 2.0*PI;
  416.     if (x > PI)
  417.       x -= 2.0*PI;
  418.     z = lon+RTOD(x);
  419.     if (z > DEGHALF)
  420.       z -= DEGREES;
  421.     j = (int) (Mod(DEGHALF-z+degree)*(real)SCALE);
  422.     DrawColor(elemcolor[_EAR]);
  423.     DrawLine(j, y1+unit*4, j, y2-unit*1);
  424.     end2[i*2-1] = (real) j;
  425.     y = RTOD(planet2[i]);
  426.     k = (int) ((91.0-y)*(real)SCALE);
  427.     DrawColor(hilite);
  428.     DrawBlock(j-1, k-1, j+1, k+1);
  429.     DrawColor(off);
  430.     DrawBlock(j, k, j, k);
  431.  
  432.     /* Draw Nadir lines assuming we aren't in bonus chart mode. */
  433.  
  434.     if (!xbonus) {
  435.       j += 180*SCALE;
  436.       if (j > chartx-2)
  437.         j -= (chartx-2);
  438.       end1[i*2-1] = (real) j;
  439.       DrawColor(elemcolor[_WAT]);
  440.       DrawLine(j, y1+unit*2, j, y2-unit*2);
  441.     }
  442.   }
  443.  
  444.   /* Now, normally, unless we are in bonus chart mode, we will go on to draw */
  445.   /* the Ascendant and Descendant lines here.                                */
  446.  
  447.   longm = DTOR(Mod(MC+lon));
  448.   if (!xbonus) for (i = 1; i <= total; i++) if (Proper(i)) {
  449.     xold1 = xold2 = -1000;
  450.  
  451.     /* Hack: Normally we draw the Ascendant and Descendant line segments  */
  452.     /* simultaneously. However, for the PostScript and metafile stroke    */
  453.     /* graphics, this will case the file to get inordinately large due to */
  454.     /* the constant thrashing between the Asc and Desc colors. Hence for  */
  455.     /* these charts only, we'll do two passes for Asc and Desc.           */
  456.     stroke = psfile || metafile;
  457.     for (l = 0; l <= stroke; l++)
  458.  
  459.     for (lat = (real)lat1; lat <= (real)lat2;
  460.       lat += 1.0/(real)(SCALE/scalet)) {
  461.  
  462.       /* First compute and draw the current segment of Ascendant line. */
  463.  
  464.       j = (int) ((91.0-lat)*(real)SCALE);
  465.       ad = tan(planet2[i])*tan(DTOR(lat));
  466.       if (ad*ad > 1.0)
  467.         ad = LARGE;
  468.       else {
  469.         ad = ASIN(ad);
  470.         oa = planet1[i]-ad;
  471.         if (oa < 0.0)
  472.           oa += 2.0*PI;
  473.         am = oa-PI/2.0;
  474.         if (am < 0.0)
  475.           am += 2.0*PI;
  476.         z = longm-am;
  477.         if (z < 0.0)
  478.           z += 2.0*PI;
  479.         if (z > PI)
  480.           z -= 2.0*PI;
  481.         z = RTOD(z);
  482.         k = (int) (Mod(DEGHALF-z+degree)*(real)SCALE);
  483.         if (!stroke || !l) {
  484.           DrawColor(elemcolor[_FIR]);
  485.           DrawWrap(xold1, j+scalet, k, j, 1, chartx-2);
  486.           if (lat == (real) lat1) {                        /* Line segment */
  487.             DrawLine(k, y1, k, y1+unit*4);                 /* pointing to  */
  488.             end2[i*2] = (real) k;                          /* Ascendant.   */
  489.           }
  490.         } else if (lat == (real) lat1)
  491.           end2[i*2] = (real) k;
  492.         xold1 = k;
  493.       }
  494.  
  495.       /* The curving Ascendant and Descendant lines actually touch each at  */
  496.       /* low latitudes. Sometimes when we start out, a particular planet's  */
  497.       /* lines haven't appeared yet, i.e. we are scanning at a latitude     */
  498.       /* where our planet's lines don't exist. If this is the case, then    */
  499.       /* when they finally do start, draw a thin horizontal line connecting */
  500.       /* the Ascendant and Descendant lines so they don't just start in     */
  501.       /* space. Note that these connected lines aren't labeled with glyphs. */
  502.  
  503.       if (ad == LARGE) {
  504.         if (xold1 >= 0) {
  505.           if (!stroke || !l) {
  506.             DrawColor(gray);
  507.             DrawWrap(xold1, j+1, xold2, j+1, 1, chartx-2);
  508.           }
  509.           lat = DEGQUAD;
  510.         }
  511.       } else {
  512.  
  513.       /* Then compute and draw corresponding segment of Descendant line. */
  514.  
  515.         od = planet1[i]+ad;
  516.         dm = od+PI/2.0;
  517.         z = longm-dm;
  518.         if (z < 0.0)
  519.           z += 2.0*PI;
  520.         if (z > PI)
  521.           z -= 2.0*PI;
  522.         z = RTOD(z);
  523.         k = (int) (Mod(DEGHALF-z+degree)*(real)SCALE);
  524.         if (xold2 < 0 && lat > (real)lat1 && (!stroke || l)) {
  525.           DrawColor(gray);
  526.           DrawWrap(xold1, j, k, j, 1, chartx-2);
  527.         }
  528.         if (!stroke || l) {
  529.           DrawColor(elemcolor[_AIR]);
  530.           DrawWrap(xold2, j+scalet, k, j, 1, chartx-2);
  531.           if (lat == (real)lat1)                           /* Line segment */
  532.             DrawLine(k, y1, k, y1+unit*2);                 /* pointing to  */
  533.         }                                                  /* Descendant.  */
  534.         xold2 = k;
  535.       }
  536.     }
  537. #endif /* MATRIX */
  538.  
  539.     /* Draw segments pointing to top of Ascendant and Descendant lines. */
  540.  
  541.     if (ad != LARGE) {
  542.       DrawColor(elemcolor[_FIR]);
  543.       DrawLine(xold1, y2, xold1, y2-unit*1);
  544.       DrawColor(elemcolor[_AIR]);
  545.       DrawLine(k, y2, k, y2-unit*2);
  546.       end1[i*2] = (real) k;
  547.     }
  548.   }
  549.   DrawColor(maincolor[5]);
  550.   DrawPoint((int)((181.0-Lon)*(real)SCALE),
  551.     (int)((91.0-Lat)*(real)SCALE));
  552.  
  553.   /* Determine where to draw the planet glyphs. We have four sets of each    */
  554.   /* planet - each planet's glyph appearing in the chart up to four times -  */
  555.   /* one for each type of line. The Midheaven and Ascendant lines are always */
  556.   /* labeled at the bottom of the chart, while the Nadir and Midheaven lines */
  557.   /* at the top. Therefore we need to place two sets of glyphs, twice.       */
  558.  
  559.   for (i = 1; i <= total*2; i++) {
  560.     symbol1[i] = end1[i];
  561.     symbol2[i] = end2[i];
  562.   }
  563.   FillSymbolLine(symbol1);
  564.   FillSymbolLine(symbol2);
  565.  
  566.   /* Now actually draw the planet glyphs. */
  567.  
  568.   for (i = 1; i <= total*2; i++) {
  569.     j = (i+1)/2;
  570.     if (Proper(j)) {
  571.       if ((turtlex = (int) symbol1[i]) > 0 && xlabel) {
  572.         DrawColor(ret[j] < 0.0 ? gray : on);
  573.         DrawDash((int) end1[i], y2-unit*2, (int) symbol1[i], y2-unit*4,
  574.           (ret[i] < 0.0 ? 1 : 0) - xcolor);
  575.         DrawObject(j, turtlex, y2-unit*10);
  576.       }
  577.       if ((turtlex = (int) symbol2[i]) > 0) {
  578.         DrawColor(ret[j] < 0.0 ? gray : on);
  579.         DrawDash((int) end2[i], y1+unit*4, (int) symbol2[i], y1+unit*8,
  580.           (ret[i] < 0.0 ? 1 : 0) - xcolor);
  581.         DrawObject(j, turtlex, y1+unit*14);
  582.         DrawTurtle(objectdraw[i & 1 ? _MC : _ASC], (int) symbol2[i],
  583.           y1+unit*24);
  584.       }
  585.     }
  586.   }
  587. }
  588.  
  589.  
  590. /* Draw an aspect and midpoint grid in the window, with planets labeled down */
  591. /* the diagonal. This chart is done when the -g switch is combined with the  */
  592. /* -X switch. The chart always has a certain number of cells; hence based    */
  593. /* how the restrictions are set up, there may be blank columns and rows,     */
  594. /* or else only the first number of unrestricted objects will be included.   */
  595.  
  596. void XChartGrid()
  597. {
  598.   char string[STRING];
  599.   int unit, siz, x, y, i, j, k;
  600.   colpal c;
  601.  
  602.   unit = CELLSIZE*SCALE; siz = gridobjects*unit;
  603.   CreateGrid(xbonus);
  604.  
  605.   /* Loop through each cell in each row and column of grid. */
  606.  
  607.   for (y = 1, j = 0; y <= gridobjects; y++) {
  608.     do {
  609.       j++;
  610.     } while (ignore[j] && j <= total);
  611.     DrawColor(gray);
  612.     DrawDash(0, y*unit, siz, y*unit, !xcolor);
  613.     DrawDash(y*unit, 0, y*unit, siz, !xcolor);
  614.     if (j <= total) for (x = 1, i = 0; x <= gridobjects; x++) {
  615.       do {
  616.         i++;
  617.       } while (ignore[i] && i <= total);
  618.       if (i <= total) {
  619.         turtlex = x*unit-unit/2;
  620.         turtley = y*unit-unit/2 - (SCALE/scalet > 2 ? 5*scalet : 0);
  621.  
  622.         /* If this is an aspect cell, draw glyph of aspect in effect. */
  623.  
  624.         if (xbonus ? x > y : x < y) {
  625.           DrawColor(c = aspectcolor[grid->n[i][j]]);
  626.           DrawAspect(grid->n[i][j], turtlex, turtley);
  627.  
  628.         /* If this is a midpoint cell, draw glyph of sign of midpoint. */
  629.  
  630.         } else if (xbonus ? x < y : x > y) {
  631.           DrawColor(c = signcolor(grid->n[i][j]));
  632.           DrawSign(grid->n[i][j], turtlex, turtley);
  633.  
  634.         /* For cells on main diagonal, draw glyph of planet. */
  635.  
  636.         } else {
  637.           DrawColor(hilite);
  638.           DrawEdge((y-1)*unit, (y-1)*unit, y*unit, y*unit);
  639.           DrawObject(i, turtlex, turtley);
  640.         }
  641.  
  642.         /* When the scale size is 300, we can print text in each cell: */
  643.  
  644.         if (SCALE/scalet > 2 && xlabel) {
  645.           k = abs(grid->v[i][j]);
  646.  
  647.           /* For the aspect portion, print the orb in degrees and minutes. */
  648.  
  649.           if (xbonus ? x > y : x < y) {
  650.             if (grid->n[i][j])
  651.               sprintf(string, "%c%d %02d'", k != grid->v[i][j] ? '-' : '+',
  652.                 k/60, k%60);
  653.             else
  654.               sprintf(string, "");
  655.  
  656.           /* For the midpoint portion, print the degrees and minutes. */
  657.  
  658.           } else if (xbonus ? x < y : x > y)
  659.             sprintf(string, "%2d %02d'", k/60, k%60);
  660.  
  661.           /* For the main diagonal, print degree and sign of each planet. */
  662.  
  663.           else {
  664.             c = signcolor(grid->n[i][j]);
  665.             sprintf(string, "%c%c%c %02d", SIGNAM(grid->n[i][j]), k);
  666.           }
  667.           DrawColor(c);
  668.           DrawText(string, x*unit-unit/2, y*unit-3*scalet, TRUE);
  669.         }
  670.       }
  671.     }
  672.   }
  673. }
  674.  
  675.  
  676. /* Draw the local horizon, and draw in the planets where they are at the */
  677. /* time in question, as done when the -Z is combined with the -X switch. */
  678.  
  679. void XChartHorizon()
  680. {
  681.   real lon, lat,
  682.     lonz[TOTAL+1], latz[TOTAL+1], azi[TOTAL+1], alt[TOTAL+1];
  683.   int x[TOTAL+1], y[TOTAL+1], m[TOTAL+1], n[TOTAL+1],
  684.     cx = chartx / 2, cy = charty / 2, unit = 12*SCALE,
  685.     x1, y1, x2, y2, xs, ys, i, j, k, l;
  686.  
  687.   /* Make a slightly smaller rectangle within the window to draw the planets */
  688.   /* in. Make segments on all four edges marking 5 degree increments.        */
  689.  
  690.   x1 = y1 = unit/2; x2 = chartx-x1; y2 = charty-y1;
  691.   xs = x2-x1; ys = y2-y1;
  692.   DrawColor(hilite);
  693.   for (i = 0; i < 180; i += 5) {
  694.     j = y1+(int)((real)i*(real)ys/DEGHALF);
  695.     k = (2+(i%10 == 0)+2*(i%30 == 0))*scalet;
  696.     DrawLine(x1+1, j, x1+1+k, j);
  697.     DrawLine(x2-1, j, x2-1-k, j);
  698.   }
  699.   for (i = 0; i < DEGR; i += 5) {
  700.     j = x1+(int)((real)i*(real)xs/DEGREES);
  701.     k = (2+(i%10 == 0)+2*(i%30 == 0))*scalet;
  702.     DrawLine(j, y1+1, j, y1+1+k);
  703.     DrawLine(j, y2-1, j, y2-1-k);
  704.   }
  705.  
  706.   /* Draw vertical lines dividing our rectangle into four areas. In our     */
  707.   /* local space chart, the middle line represents due south, the left line */
  708.   /* due east, the right line due west, and the edges due north. A fourth   */
  709.   /* horizontal line divides that which is above and below the horizon.     */
  710.  
  711.   DrawColor(gray);
  712.   DrawDash(cx, y1, cx, y2, 1);
  713.   DrawDash((cx+x1)/2, y1, (cx+x1)/2, y2, 1);
  714.   DrawDash((cx+x2)/2, y1, (cx+x2)/2, y2, 1);
  715.   DrawColor(on);
  716.   DrawEdge(x1, y1, x2, y2);
  717.   DrawDash(x1, cy, x2, cy, 1);
  718.  
  719.   /* Calculate the local horizon coordinates of each planet. First convert */
  720.   /* zodiac position and declination to zenith longitude and latitude.     */
  721.  
  722.   lon = DTOR(Mod(Lon)); lat = DTOR(Lat);
  723.   for (i = 1; i <= total; i++) {
  724.     lonz[i] = DTOR(planet[i]); latz[i] = DTOR(planetalt[i]);
  725.     EclToEqu(&lonz[i], &latz[i]);
  726.   }
  727.   for (i = 1; i <= total; i++) if (Proper(i)) {
  728.     lonz[i] = DTOR(Mod(RTOD(lonz[_MC]-lonz[i]+PI/2.0)));
  729.     EquToLocal(&lonz[i], &latz[i], PI/2.0-lat);
  730.     azi[i] = DEGREES-RTOD(lonz[i]); alt[i] = RTOD(latz[i]);
  731.     x[i] = x1+(int)((real)xs*(Mod(DEGQUAD-azi[i]))/DEGREES+ROUND);
  732.     y[i] = y1+(int)((real)ys*(DEGQUAD-alt[i])/DEGHALF+ROUND);
  733.     m[i] = x[i]; n[i] = y[i]+unit/2;
  734.   }
  735.  
  736.   /* As in the DrawGlobe() routine, we now determine where to draw the   */
  737.   /* glyphs in relation to the actual points, so that the glyphs aren't  */
  738.   /* drawn on top of each other if possible. Again, we assume that we'll */
  739.   /* put the glyph right under the point, unless there would be some     */
  740.   /* overlap and the above position is better off.                       */
  741.  
  742.   for (i = 1; i <= total; i++) if (Proper(i)) {
  743.     k = l = chartx+charty;
  744.     for (j = 1; j < i; j++) if (Proper(j)) {
  745.       k = MIN(k, abs(m[i]-m[j])+abs(n[i]-n[j]));
  746.       l = MIN(l, abs(m[i]-m[j])+abs(n[i]-unit-n[j]));
  747.     }
  748.     if (k < unit || l < unit)
  749.       if (k < l)
  750.         n[i] -= unit;
  751.   }
  752.   for (i = total; i >= 1; i--) if (Proper(i))    /* Draw planet's glyph. */
  753.     DrawObject(i, m[i], n[i]);
  754.   for (i = total; i >= 1; i--) if (Proper(i)) {
  755.     DrawColor(objectcolor[i]);
  756.     if (!xbonus || i > BASE)
  757.       DrawPoint(x[i], y[i]);    /* Draw small or large dot */
  758.     else                        /* near glyph indicating   */
  759.       DrawSpot(x[i], y[i]);     /* exact local location.   */
  760.   }
  761. }
  762.  
  763.  
  764. /* Draw the local horizon, and draw in the planets where they are at the  */
  765. /* time in question. This chart is done when the -Z0 is combined with the */
  766. /* -X switch. This is an identical function to XChartHorizon(); however,  */
  767. /* that routine's chart is entered on the horizon and meridian. Here we   */
  768. /* center the chart around the center of the sky straight up from the     */
  769. /* local horizon, with the horizon itself being an encompassing circle.   */
  770.  
  771. void XChartHorizonSky()
  772. {
  773.   real lon, lat, rx, ry, s, a, sqr2,
  774.     lonz[TOTAL+1], latz[TOTAL+1], azi[TOTAL+1], alt[TOTAL+1];
  775.   int x[TOTAL+1], y[TOTAL+1], m[TOTAL+1], n[TOTAL+1],
  776.     cx = chartx / 2, cy = charty / 2, unit = 12*SCALE, i, j, k, l;
  777.  
  778.   /* Draw a circle in window to indicate horizon line, lines dividing   */
  779.   /* the window into quadrants to indicate n/s and w/e meridians, and   */
  780.   /* segments on these lines and the edges marking 5 degree increments. */
  781.  
  782.   sqr2 = sqrt(2.0);
  783.   DrawColor(gray);
  784.   DrawDash(cx, 0, cx, charty-1, 1);
  785.   DrawDash(0, cy, chartx-1, cy, 1);
  786.   DrawColor(hilite);
  787.   for (i = -125; i <= 125; i += 5) {
  788.     k = (2+(i/10*10 == i ? 1 : 0)+(i/30*30 == i ? 2 : 0))*scalet;
  789.     s = 1.0/(DEGQUAD*sqr2);
  790.     j = cy+(int)(s*cy*i);
  791.     DrawLine(cx-k, j, cx+k, j);
  792.     j = cx+(int)(s*cx*i);
  793.     DrawLine(j, cy-k, j, cy+k);
  794.   }
  795.   for (i = 5; i < 55; i += 5) {
  796.     k = (2+(i/10*10 == i ? 1 : 0)+(i/30*30 == i ? 2 : 0))*scalet;
  797.     s = 1.0/(DEGHALF-DEGQUAD*sqr2);
  798.     j = (int)(s*cy*i);
  799.     DrawLine(0, j, k, j);
  800.     DrawLine(0, charty-1-j, k, charty-1-j);
  801.     DrawLine(chartx-1, j, chartx-1-k, j);
  802.     DrawLine(chartx-1, charty-1-j, chartx-1-k, charty-1-j);
  803.     j = (int)(s*cx*i);
  804.     DrawLine(j, 0, j, k);
  805.     DrawLine(chartx-1-j, 0, chartx-1-j, k);
  806.     DrawLine(j, charty-1, j, charty-1-k);
  807.     DrawLine(chartx-1-j, charty-1, chartx-1-j, charty-1-k);
  808.   }
  809.   rx = cx/sqr2; ry = cy/sqr2;
  810.   DrawColor(on);
  811.   DrawCircle(cx, cy, (int)rx, (int)ry);
  812.   InitCircle();
  813.   for (i = 0; i < DEGR; i += 5) {
  814.     k = (2+(i/10*10 == i ? 1 : 0)+(i/30*30 == i ? 2 : 0))*scalet;
  815.     DrawLine(cx+(int)((rx-k)*circ->x[i]), cy+(int)((ry-k)*circ->y[i]),
  816.       cx+(int)((rx+k)*circ->x[i]), cy+(int)((ry+k)*circ->y[i]));
  817.   }
  818.  
  819.   /* Calculate the local horizon coordinates of each planet. First convert */
  820.   /* zodiac position and declination to zenith longitude and latitude.     */
  821.  
  822.   lon = DTOR(Mod(Lon)); lat = DTOR(Lat);
  823.   for (i = 1; i <= total; i++) {
  824.     lonz[i] = DTOR(planet[i]); latz[i] = DTOR(planetalt[i]);
  825.     EclToEqu(&lonz[i], &latz[i]);
  826.   }
  827.   for (i = 1; i <= total; i++) if (Proper(i)) {
  828.     lonz[i] = DTOR(Mod(RTOD(lonz[_MC]-lonz[i]+PI/2.0)));
  829.     EquToLocal(&lonz[i], &latz[i], PI/2.0-lat);
  830.     azi[i] = a = DEGREES-RTOD(lonz[i]); alt[i] = DEGQUAD-RTOD(latz[i]);
  831.     s = alt[i]/DEGQUAD;
  832.     x[i] = cx+(int)(rx*s*COSD(DEGHALF+azi[i])+ROUND);
  833.     y[i] = cy+(int)(ry*s*SIND(DEGHALF+azi[i])+ROUND);
  834.     if (!ISCHART(x[i], y[i]))
  835.       x[i] = -1000;
  836.     m[i] = x[i]; n[i] = y[i]+unit/2;
  837.   }
  838.  
  839.   /* As in the DrawGlobe() routine, we now determine where to draw the   */
  840.   /* glyphs in relation to the actual points, so that the glyphs aren't  */
  841.   /* drawn on top of each other if possible. Again, we assume that we'll */
  842.   /* put the glyph right under the point, unless there would be some     */
  843.   /* overlap and the above position is better off.                       */
  844.  
  845.   for (i = 1; i <= total; i++) if (Proper(i)) {
  846.     k = l = chartx+charty;
  847.     for (j = 1; j < i; j++) if (Proper(j)) {
  848.       k = MIN(k, abs(m[i]-m[j])+abs(n[i]-n[j]));
  849.       l = MIN(l, abs(m[i]-m[j])+abs(n[i]-unit-n[j]));
  850.     }
  851.     if (k < unit || l < unit)
  852.       if (k < l)
  853.         n[i] -= unit;
  854.   }
  855.   for (i = total; i >= 1; i--) if (m[i] >= 0 && Proper(i))    /* Draw glyph. */
  856.     DrawObject(i, m[i], n[i]);
  857.   for (i = total; i >= 1; i--) if (x[i] >= 0 && Proper(i)) {
  858.     DrawColor(objectcolor[i]);
  859.     if (!xbonus || i > BASE)
  860.       DrawPoint(x[i], y[i]);    /* Draw small or large dot */
  861.     else                        /* near glyph indicating   */
  862.       DrawSpot(x[i], y[i]);     /* exact local location.   */
  863.   }
  864. }
  865.  
  866.  
  867. /* Draw a chart depicting an aerial view of the solar system in space, with */
  868. /* all the planets drawn around the Sun, and the specified central planet   */
  869. /* in the middle, as done when the -S is combined with the -X switch.       */
  870.  
  871. void XChartSpace()
  872. {
  873.   int x[TOTAL+1], y[TOTAL+1], m[TOTAL+1], n[TOTAL+1],
  874.     cx = chartx / 2, cy = charty / 2, unit, x1, y1, x2, y2, i, j, k, l;
  875.   real sx, sy, sz = 30.0, xp, yp, a;
  876.  
  877.   unit = MAX(xtext*12, 6*SCALE);
  878.   x1 = unit; y1 = unit; x2 = chartx-1-unit; y2 = charty-1-unit;
  879.   unit = 12*SCALE;
  880.  
  881.   /* Determine the scale of the window. For a scale size of 300, make    */
  882.   /* the window 6 AU in radius (enough for inner planets out to asteroid */
  883.   /* belt). For a scale of 200, make window 30 AU in radius (enough for  */
  884.   /* planets out to Neptune). For scale of 100, make it 90 AU in radius  */
  885.   /* (enough for all planets including the orbits of the uranians.)      */
  886.  
  887.   if (SCALE < 2)
  888.     sz = 90.0;
  889.   else if (SCALE > 2)
  890.     sz = 6.0;
  891.   sx = (real)(cx-x1)/sz; sy = (real)(cy-y1)/sz;
  892.   for (i = 0; i <= BASE; i++) if (Proper(i)) {
  893.  
  894.     /* Determine what glyph corresponds to our current planet. Normally the */
  895.     /* array indices are the same, however we have to do some swapping for  */
  896.     /* non-geocentric based charts where a planet gets replaced with Earth. */
  897.  
  898.     if (centerplanet == 0)
  899.       j = i < 2 ? 1-i : i;
  900.     else if (centerplanet == 1)
  901.       j = i;
  902.     else
  903.       j = i == 0 ? centerplanet : (i == centerplanet ? 0 : i);
  904.     xp = spacex[j]; yp = spacey[j];
  905.     x[i] = cx-(int)(xp*sx); y[i] = cy+(int)(yp*sy);
  906.     m[i] = x[i]; n[i] = y[i]+unit/2;
  907.   }
  908.  
  909.   /* As in the DrawGlobe() routine, we now determine where to draw the   */
  910.   /* glyphs in relation to the actual points, so that the glyphs aren't  */
  911.   /* drawn on top of each other if possible. Again, we assume that we'll */
  912.   /* put the glyph right under the point, unless there would be some     */
  913.   /* overlap and the above position is better off.                       */
  914.  
  915.   for (i = 0; i <= BASE; i++) if (Proper(i)) {
  916.     k = l = chartx+charty;
  917.     for (j = 0; j < i; j++) if (Proper(j)) {
  918.       k = MIN(k, abs(m[i]-m[j])+abs(n[i]-n[j]));
  919.       l = MIN(l, abs(m[i]-m[j])+abs(n[i]-unit-n[j]));
  920.     }
  921.     if (k < unit || l < unit)
  922.       if (k < l)
  923.         n[i] -= unit;
  924.   }
  925.  
  926.   /* Draw the 12 sign boundaries from the center body to edges of screen. */
  927.  
  928.   a = Mod(RTOD(Angle(spacex[_JUP], spacey[_JUP]))-planet[_JUP]);
  929.   DrawColor(gray);
  930.   for (i = 0; i < SIGNS; i++) {
  931.     k = cx+2*(int)((real)cx*COSD((real)i*30.0+a));
  932.     l = cy+2*(int)((real)cy*SIND((real)i*30.0+a));
  933.     DrawClip(cx, cy, k, l, x1, y1, x2, y2, 1);
  934.   }
  935.   DrawColor(hilite);
  936.   DrawEdge(x1, y1, x2, y2);
  937.   for (i = BASE; i >= 0; i--)
  938.     if (Proper(i) && ISLEGAL(m[i], n[i], x1, y1, x2, y2))
  939.       DrawObject(i, m[i], n[i]);
  940.   for (i = BASE; i >= 0; i--)
  941.     if (Proper(i) && ISLEGAL(x[i], y[i], x1, y1, x2, y2)) {
  942.       DrawColor(objectcolor[i]);
  943.       if (!xbonus || i > BASE)
  944.         DrawPoint(x[i], y[i]);    /* Draw small or large dot */
  945.       else                        /* near glyph indicating   */
  946.         DrawSpot(x[i], y[i]);     /* exact local location.   */
  947.     }
  948. }
  949.  
  950.  
  951. /* Draw a chart showing a graphical ephemeris for the given month (or year */
  952. /* if -Ey in effect), with the date on the vertical access and the zodiac  */
  953. /* on the horizontal, as done when the -E is combined with the -X switch.  */
  954.  
  955. void XChartEphemeris()
  956. {
  957.   real symbol[TOTAL*2+1];
  958.   char string[4];
  959.   int yea, unit = 6*SCALE, daytot, d = 1, day, mon, monsiz,
  960.     x1, y1, x2, y2, xs, ys, m, n, u, v, i, j;
  961.  
  962.   yea = (exdisplay & DASHEy) > 0;    /* Is this -Ey -X or just -E -X? */
  963.   if (yea) {
  964.     daytot = DayInYear(Yea);
  965.     day = 1; mon = 1; monsiz = 31;
  966.   } else
  967.     daytot = DayInMonth(Mon, Yea);
  968.   x1 = yea ? 30 : 24; y1 = unit*2; x2 = chartx - x1; y2 = charty - y1;
  969.   xs = x2 - x1; ys = y2 - y1;
  970.  
  971.   /* Display glyphs of the zodiac along the bottom axis. */
  972.   for (i = 1; i <= SIGNS+1; i++) {
  973.     m = x1 + xs * (i-1) / 12;
  974.     j = i > SIGNS ? 1 : i;
  975.     DrawColor(signcolor(j));
  976.     DrawSign(j, m, y2 + unit);
  977.     DrawColor(gray);
  978.     DrawDash(m, y1, m, y2, 2);
  979.   }
  980.  
  981.   /* Loop and display planet movements for one day segment. */
  982.   while (d <= daytot + 1) {
  983.     n = v;
  984.     v = y1 + MULTDIV(ys, d-1, daytot);
  985.     if (!yea || day == 1) {
  986.       DrawColor(gray);
  987.       DrawDash(x1, v, x2, v, 1);    /* Marker line for day or month. */
  988.     }
  989.     if (d > 1)
  990.       for (i = 1; i <= total; i++)
  991.         planet1[i] = planet[i];
  992.     if (yea) {
  993.       MM = mon; DD = day;
  994.     } else {
  995.       MM = Mon; DD = d;
  996.     }
  997.     YY = Yea; TT = 0.0; ZZ = defzone; OO = deflong; AA = deflat;
  998.     CastChart(TRUE);
  999.  
  1000.     /* Draw planet glyphs along top of chart. */
  1001.     if (d < 2) {
  1002.       for (i = 1; i <= total; i++) {
  1003.         symbol[i*2-1] = -LARGE;
  1004.         if (!Proper(i) || (i == _MOO && xbonus))
  1005.           symbol[i*2] = -LARGE;
  1006.         else
  1007.           symbol[i*2] = planet[i];
  1008.       }
  1009.       FillSymbolLine(symbol);
  1010.       for (i = total; i >= 1; i--)
  1011.         if (symbol[i*2] >= 0.0)
  1012.           DrawObject(i, x1 + (int)((real)xs * symbol[i*2] / DEGREES), unit);
  1013.  
  1014.     /* Draw a line segment for each object during this time section. */
  1015.     } else
  1016.       for (i = total; i >= 1; i--) {
  1017.         if (!Proper(i) || (i == _MOO && xbonus))
  1018.           continue;
  1019.         m = x1 + (int)((real)xs * planet1[i] / DEGREES);
  1020.         u = x1 + (int)((real)xs * planet[i]  / DEGREES);
  1021.         DrawColor(objectcolor[i]);
  1022.         DrawWrap(m, n, u, v, x1, x2, objectcolor[i]);
  1023.       }
  1024.  
  1025.     /* Label months or days in the month along the left and right edges. */
  1026.     if (d <= daytot && (!yea || day == 1)) {
  1027.       if (yea) {
  1028.         sprintf(string, "%c%c%c", MONNAM(mon));
  1029.         i = (mon == Mon);
  1030.       } else {
  1031.         sprintf(string, "%2d", d);
  1032.         i = (d == Day);
  1033.       }
  1034.       DrawColor(i ? on : hilite);
  1035.       DrawText(string,     FONTX   *scalet, v + (FONTY-2)*scalet, -1);
  1036.       DrawText(string, x2+(FONTX-1)*scalet, v + (FONTY-2)*scalet, -1);
  1037.     }
  1038.  
  1039.     /* Now increment the day counter. For a month we always go up by one. */
  1040.     /* For a year we go up by four or until the end of the month reached. */
  1041.     if (yea) {
  1042.       day += 4;
  1043.       if (day > monsiz) {
  1044.         d += 4-(day-monsiz-1);
  1045.         if (d <= daytot + 1) {
  1046.           mon++;
  1047.           monsiz = DayInMonth(mon, Yea);
  1048.           day = 1;
  1049.         }
  1050.       } else
  1051.         d += 4;
  1052.     } else
  1053.       d++;
  1054.   }
  1055.   DrawColor(hilite);
  1056.   DrawEdge(x1, y1, x2, y2);
  1057.  
  1058.   MM = Mon; DD = Day; TT = Tim;    /* Recast original chart. */
  1059.   CastChart(TRUE);
  1060. }
  1061. #endif /* GRAPH */
  1062.  
  1063. /* xcharts.c */
  1064.