Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!ucsd!sdcc6!sdcc13!pa1099 From: pa1099@sdcc13.ucsd.edu (Mark B. Hanson) Newsgroups: comp.lang.postscript Subject: pscal update [code!] Keywords: pscal, phase of moon, neat-o Message-ID: <7788@sdcc6.ucsd.edu> Date: 24 Feb 90 03:01:10 GMT Sender: news@sdcc6.ucsd.edu Distribution: inet Lines: 748 Hi, I've updated pscal so that it will take a -m option and put a little picture of the phase of the moon in the corner of each day. The program actually calculates what the phase should be and then draws it accordingly. It is not super accurate, but I've tested it against every recorded full moon that I could get my hands on and it was pretty darn close. The little pictures may be a tiny bit off sometimes. This is the first significant PostScript program I've worked on, so if I've totally over done it or if you find any bugs, don't hesitate to write me. It would also be nice to hear from you if you like the moons. Any negative comments about my indenting style will be met with a reply consisting of the source code for pspp. :-) There are some comments in the code, so look there for more info, or write me if you must. I changed the 1000 to 400 in two procedures that dealt with leap years and modified prtevent so that events that fell on double days would get printed. That didn't seem to work before I changed it. Anyway, try it out; if you like it or find problems with it, send me e-mail at the address below. Should I post this to alt.sources also? Any opinions? Thanks, Mark B. Hanson cs62a12@wind.ucsd.edu 128.54.20.129 -------------------------cut-on-the-dotted-line-------------------------- #!/bin/sh # # NAME: # pscal # # SYNOPSIS: # pscal [-Pprinter] [other option flags] month year # # DESCRIPTION: # `Pscal' is a PostScript program to print calendars. # # The file $HOME/.holiday is read and used to print short messages # on specified days. The .holiday file should consist of lines of # the form # month:day:message string # Messages should be 20 characters or less, with no more than 6 # messages per day. No spaces should appear from the beginning # of a line until after the second colon. # Month and day should be numbers in the obvious ranges. # 12/89 - The holiday checking has been loosened up in that the # following takes place: # 1. The Shell Variable EFILE is used preferentially # 2. Then the file Events in the current directory is used # 3. Finally the $HOME/.holiday file is used. # The whole process can be turned off by setting EFILE=/dev/null. # # OPTIONS: # Any argument whose first character is '-' is passed on to lpr. # The shell variables BANNER, LFOOT, CFOOT, and RFOOT become a # top centered banner, and left, centered, or right justified # footers respectively. As in: # # BANNER="Schedule 1"; CFOOT=Preliminary; pscal 4 90 # # AUTHOR: # Patrick Wood # Copyright (C) 1987 by Pipeline Associates, Inc. # Permission is granted to modify and distribute this free of charge. # # HISTORY: # @Original From: patwood@unirot.UUCP (Patrick Wood) # @Shell stuff added 3/9/87 by King Ables # @Made pretty by tjt 1988 # @Holiday and printer flag passing hacks added Dec 1988 # @ by smann@june.cs.washington.edu # @Used the better looking version with 5 rows of days rather than 6 # @ hacked together with holiday and banner/footnotes added # @ by Joe (No Relation) Wood, 12/89, jlw@lzga.ATT.COM # @Fixed "-R" (didn't work at all; now it at least works on 8.5x11) # @Also fixed handling of unrecognized arguments # @ by Jeff Mogul, 1/90, mogul@decwrl.dec.com # @Moon routines added; 1000 changed to 400 in isleap and startday; # @ fixed bug involving printing events on isdouble 30,31 days. # @ by Mark Hanson, 2/90, cs62a12@wind.ucsd.edu # # BUGS: # `Pscal' doesn't work for months before 1753 (weird stuff happened # in September, 1752). # # A better format for the dates of holidays would be nice. # An escape to allow holiday messages to be raw PostScript would # also be nice. # The holiday messages should be handled more intelligently (ie, # the messages should be clipped to the day). # USAGE="Usage: pscal [ -Rrtm ] [ -F hfont ] [ -f font ] [ month [ year ] ]" TFONT=Times-Bold DFONT=Helvetica-Bold EFONT=Times-Roman ROTATE=90 SCALE="1.0 1.0" TRANSLATE="50 -120" MOON="false" LPR="lpr" # here you should put whatever you need to direct the output to # a laser printer; or you can replace it with "cat" or use the # -t option if you want the the code to go to standard output. while test $# != 0 do case $1 in -m) MOON="true"; shift;; -P) test $# -lt 2 && { echo "$USAGE" 1>&2; exit 1; } eval ENVAR="$1$2"; shift 2;; -P*) eval ENVAR=$1; shift 1;; -F) test $# -lt 2 && { echo "$USAGE" 1>&2; exit 1; } TFONT="$2"; shift 2;; -F*) TFONT=`echo $1 | sed -n 1s/-.//p`; shift 1;; -f) test $# -lt 2 && { echo "$USAGE" 1>&2; exit 1; } DFONT="$2"; shift 2;; -f*) DFONT=`echo $1 | sed -n 1s/-.//p`; shift 1;; -t) LPR="cat"; shift 1;; -r) ROTATE=90; shift 1;; -R) ROTATE=0; SCALE="0.75 0.75"; TRANSLATE="50 900"; shift 1;; --|-) break;; -*) eval ENVAR=\"$ENVAR $1\"; shift 1;; *) break esac done test $# -gt 2 && { echo "$USAGE" 1>&2; exit 1; } case $# in 0) set `date`; YEAR=$6 MONTH=`case $2 in Jan) echo 1;;Feb) echo 2;;Mar) echo 3;;Apr) echo 4;; May) echo 5;;Jun) echo 6;;Jul) echo 7;;Aug) echo 8;; Sep) echo 9;;Oct) echo 10;;Nov) echo 11;;Dec) echo 12;;esac`;; 1) MONTH=$1; set `date`; YEAR=$6;; 2) MONTH=$1 YEAR=$2;; esac if [ -n "$EFILE" -a -r "$EFILE" ] then Files=$EFILE elif [ -r Events ] then Files=Events elif [ -r $HOME/.holiday ] then Files=$HOME/.holiday else Files=/dev/null fi holidays=`cat $Files | grep \^$MONTH: | awk -F: '{printf("%s ( %s",$2,$3);\ for(i = 4; i <= NF; i++) printf(":%s", $i);printf(")\n"); }'` test $YEAR -lt 100 && YEAR=`expr $YEAR + 1900` $LPR $ENVAR < returns the number of the day /theday exch def % of the year /themonth exch def /theyear exch def /dayofyear 0 def themonth 1 ne { 1 1 themonth .5 sub { /mo exch cvi def /dayofyear theyear mo ndays dayofyear add def } for } if dayofyear theday add } def % doy /findphase { % find the difference between any day and the reference /thisday exch def % day of the full moon /thismonth exch def % will probably be one off if the reference is leap yr. /thisyear exch def /daysdiff thisyear thismonth thisday doy fullyear fullmonth fullday doy sub longer mul def % try to be accurate about it /yearsdiff thisyear fullyear sub def yearsdiff 0 ne { /daysdiff daysdiff yearsdiff daysperyear mul yearsdiff 100 idiv yearsdiff 400 idiv sub sub add def } if daysdiff % return difference in days } def % findphase /shrink { 2 sqrt div } def /transmogrify { 10000 mul cvi % take a real number and 'mod it down' period 10000 mul cvi % so it is in the range 0->period mod % or -period->0 10000 div } def % the 10000's preserve the accuracy /domoon { % draw the moon at the current phase /phase exch def 0 0 radius % might as well push these on now 0 0 radius phase halfperiod lt { 270 90 arc stroke % line on right, fill on left 0 radius neg moveto 270 90 arcn } { 90 270 arc stroke % line on left, fill on right 0 radius neg moveto 270 90 arc /phase phase halfperiod sub def % get rid of top halfperiod } ifelse /phase phase quartperiod sub % scale it down to -r(root2) -> r(root2) rect mul def phase % x1 phase abs shrink % y1 need abs! phase % x2 phase abs shrink neg % y2 need abs! 0 % x3 radius neg % y3 curveto fill } def % domoon /shiftdo { startphase day longer mul add transmogrify neg period add domoon } def /drawmoons { { /fullyear 1990 def % these are the dates of a full moon, /fullmonth 2 def % any date should work if it is that /fullday 9 def % of a full moon, but I haven't tried many % I wouldn't make this reference date fall in a leap year, wierdness % will probably happen in findphase. You will probably gain or lose a day % somewhere. MBH /period 29.5306 def /daysperyear 365.2422 def /longer daysperyear 365 div def /halfperiod period 2 div def /quartperiod period 4 div def /radius 13 def /rect radius 2 sqrt mul quartperiod div def /startphase year month 0 findphase transmogrify dup 0 lt { period add } if def /start startday def /days year month ndays def gsave 0.1 setlinewidth newpath daywidth radius sub 3 sub 15 translate start daywidth mul 0 translate 1 1 days { /day exch def isdouble { % true if 30,31 - false if 23,24 (left on the stack after isdouble) { gsave radius 2 div dayheight radius 2 div sub translate 0.5 0.5 scale shiftdo grestore } { gsave radius 2 div neg radius 2 div translate 0.5 0.5 scale shiftdo grestore } ifelse } { shiftdo } ifelse day start add 1 sub weekday 6 eq { daywidth 6 mul neg dayheight neg translate } { daywidth 0 translate } ifelse } for grestore } if % don't do anything if the argument is false } def % drawmoons % % Main Program % /eventflag true def $SCALE scale $ROTATE rotate $TRANSLATE translate /submonth 0 def calendar $MOON drawmoons /eventflag false def month 1 sub 0 eq { /lmonth 12 def /lyear year 1 sub def } { /lmonth month 1 sub def /lyear year def } ifelse month 1 add 13 eq { /nmonth 1 def /nyear year 1 add def } { /nmonth month 1 add def /nyear year def } ifelse usefirst { 0 30 translate } { days_week 2 sub daywidth mul -350 translate } ifelse /submonth 1 def /year lyear def /month lmonth def gsave .138 .138 scale 12 -120 translate calendar grestore /submonth 1 def /year nyear def /month nmonth def daywidth 0 translate gsave .138 .138 scale 12 -120 translate calendar grestore showpage END-OF-CALENDAR