home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource1
/
ast40dos
/
xcharts.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-18
|
39KB
|
1,064 lines
/*
** Astrolog (Version 4.00) File: xcharts.c
**
** IMPORTANT NOTICE: the graphics database and chart display routines
** used in this program are Copyright (C) 1991-1993 by Walter D. Pullen
** (cruiser1@stein.u.washington.edu). Permission is granted to freely
** use and distribute these routines provided one doesn't sell,
** restrict, or profit from them in any way. Modification is allowed
** provided these notices remain with any altered or edited versions of
** the program.
**
** The main planetary calculation routines used in this program have
** been Copyrighted and the core of this program is basically a
** conversion to C of the routines created by James Neely as listed in
** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
** available from Matrix Software. The copyright gives us permission to
** use the routines for personal use but not to sell them or profit from
** them in any way.
**
** The PostScript code within the core graphics routines are programmed
** and Copyright (C) 1992-1993 by Brian D. Willoughby
** (brianw@sounds.wa.com). Conditions are identical to those above.
**
** The extended accurate ephemeris databases and formulas are from the
** calculation routines in the program "Placalc" and are programmed and
** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
** (alois@azur.ch). The use of that source code is subject to
** regulations made by Astrodienst Zurich, and the code is not in the
** public domain. This copyright notice must not be changed or removed
** by any user of this program.
**
** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
** X Window graphics initially programmed 10/23-29/1991.
** PostScript graphics initially programmed 11/29-30/1992.
** Last code change made 12/31/1993.
*/
#include "astrolog.h"
#ifdef GRAPH
/*
******************************************************************************
** Single Chart Graphics Subprograms.
******************************************************************************
*/
/* Given a string, draw it on the screen using the given color. The */
/* position of the text is based the saved positions of where we drew the */
/* text the last time the routine was called, being either directly below */
/* in the same column or in the same row just to the right. This is used */
/* by the sidebar drawing routine to print a list of text on the chart. */
int DrawPrint(string, m, n)
char *string;
int m, n;
{
static int x0, x, y;
if (string == NULL) { /* Null string means just initialize position. */
x0 = x = m; y = n;
return y;
}
if (y >= charty) /* Don't draw if we've scrolled off the chart bottom. */
return y;
DrawColor(m);
DrawText(string, x, y, -1);
/* If the second parameter is TRUE, we stay on the same line, otherwise */
/* when FALSE we go to the next line at the original column setting. */
if (n)
x += StringLen(string)*FONTX*scalet;
else {
x = x0;
n = y;
y += FONTY*scalet;
}
return y;
}
/* Print text showing the chart information and house and planet positions */
/* of a chart in a "sidebar" to the right of the chart in question. This */
/* is always done for the -v and -w graphic wheel charts unless the -v0 */
/* switch flag is also set, in which case none of the stuff here is done. */
void DrawInfo()
{
char string[STRING];
int elemode[4][3], elem[4], mo[3], tot, pos, abo, lef, lea, i, y, a, s;
#ifdef INTERPRET
/* Hack: Just for fun, if interpretation is active (which normally has */
/* no effect whatsoever on graphics) we'll decorate the chart a little. */
if (interpret) {
if (screenwidth & 1) {
/* If screenwidth value is odd, draw a moire pattern in each corner. */
abo = charty/(screenwidth/10);
lef = chartx/(screenwidth/10);
for (y = 0; y <= 1; y++)
for (i = 0; i <= 1; i++)
for (s = 0; s <= 1; s++)
for (a = 1; a < (s ? lef : abo)*2; a++) {
DrawColor(a & 1 ? gray : off);
DrawLine(i ? chartx-1-lef : lef, y ? charty-1-abo : abo,
s ? (i ? chartx-1-a : a) : i*(chartx-1),
s ? y*(charty-1) : (y ? charty-1-a : a));
}
} else {
/* If screenwidth is even, draw spider web lines in each corner. */
DrawColor(gray);
tot = screenwidth*3/20;
abo = charty/4;
lef = chartx/4;
for (y = 0; y <= 1; y++)
for (i = 0; i <= 1; i++)
for (a = 1; a < tot; a++)
DrawLine(i*(chartx-1), y ? (charty-1-a*abo/tot) : a*abo/tot,
i ? chartx-1-lef+a*lef/tot : lef-a*lef/tot, y*(charty-1));
}
}
#endif
if (!xtext || (exdisplay & DASHv0) > 0) /* Don't draw sidebar if */
return; /* -v0 flag is set. */
a = ansi;
ansi = FALSE;
seconds = -seconds;
DrawColor(hilite);
if (xborder)
DrawLine(chartx-1, 0, chartx-1, charty-1);
chartx += SIDET;
DrawPrint(NULL, chartx-SIDET+FONTX*scalet, FONTY*7/5*scalet);
/* Print chart header and setting information. */
sprintf(string, "%s %s", appname, VERSION);
DrawPrint(string, on, FALSE);
if (Mon == -1)
sprintf(string, "No time or space.");
else if (relation == DASHrc)
sprintf(string, "Composite chart.");
else {
sprintf(string, "%c%c%c %s", DAYNAM(DayOfWeek(Mon, Day, Yea)),
CharDate(Mon, Day, Yea, TRUE));
DrawPrint(string, hilite, FALSE);
DrawPrint(CharTime((int)floor(Tim), (int)(FRACT(dabs(Tim))*100.0)),
hilite, TRUE);
sprintf(string, " (%d:%02d GMT)", (int)(-Zon),
(int)(FRACT(dabs(Zon))*100.0+ROUND));
}
DrawPrint(string, hilite, FALSE);
DrawPrint(CharLocation(Lon, Lat, 100.0), hilite, FALSE);
sprintf(string, "%s houses.", systemname[housesystem]);
DrawPrint(string, hilite, FALSE);
sprintf(string, "%s zodiac.", operation & DASHs ? "Siderial" : "Tropical");
DrawPrint(string, hilite, FALSE);
sprintf(string, "Julian Day = %10.3f", JulianDayFromTime(T));
DrawPrint(string, hilite, FALSE);
/* Print house cusp positions. */
DrawPrint("", hilite, FALSE);
for (i = 1; i <= SIGNS; i++) {
sprintf(string, "%2d%s house: ", i, post[i]);
y = DrawPrint(string, signcolor(i), TRUE);
if (!seconds && (scale == 100 || !xfont || !xfile) && y < charty) {
s = scale;
scale = 100*scalet;
DrawSign(i, chartx-12*scalet, y-(FONTY/2-1)*scalet);
scale = s;
}
DrawPrint(CharZodiac(house[i]), signcolor(ZTOS(house[i])), FALSE);
}
/* Print planet positions. */
DrawPrint("", hilite, FALSE);
for (i = 1; i <= total; i++) if (!ignore[i]) {
sprintf(string, seconds ? "%3.3s: " : "%4.4s: ", objectname[i]);
DrawPrint(string, objectcolor[i], TRUE);
y = DrawPrint(CharZodiac(planet[i]), signcolor(ZTOS(planet[i])), TRUE);
if (!seconds && i < S_LO &&
(scale == 100 || !xfont || !xfile) && y < charty) {
s = scale;
scale = 100*scalet;
DrawObject(i, chartx-12*scalet, y-(FONTY/2-1)*scalet);
scale = s;
}
sprintf(string, "%c ", ret[i] < 0.0 ? 'R' : ' ');
DrawPrint(string, on, TRUE);
DrawPrint(CharAltitude(planetalt[i]), hilite, FALSE);
}
/* Print element table information. */
DrawPrint("", hilite, FALSE);
CreateElemTable(elemode, elem, mo, &tot, &pos, &abo, &lef, &lea);
sprintf(string, "Fire: %d, Earth: %d,", elem[_FIR], elem[_EAR]);
DrawPrint(string, hilite, FALSE);
sprintf(string, "Air : %d, Water: %d", elem[_AIR], elem[_WAT]);
DrawPrint(string, hilite, FALSE);
sprintf(string, "Car: %d, Fix: %d, Mut: %d", mo[0], mo[1], mo[2]);
DrawPrint(string, hilite, FALSE);
sprintf(string, "Yang: %d, Yin: %d", pos, tot-pos);
DrawPrint(string, hilite, FALSE);
sprintf(string, "N: %d, S: %d, W: %d, E: %d", abo, tot-abo, tot-lef, lef);
DrawPrint(string, hilite, FALSE);
seconds = -seconds;
ansi = a;
}
/* Draw a wheel chart, in which the 12 signs and houses are delineated, and */