home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d5xx
/
d523
/
psgraph.lha
/
PSGraph
/
fun.ps
next >
Wrap
Text File
|
1991-08-05
|
6KB
|
476 lines
/xconv % converts function x value to point coords.
{
%m=(sxmax-sxmin)/(xmax-xmin)
/m
sxmax sxmin sub
xmax xmin sub
div
def
%b=(sxmin-m*xmin)
/b
sxmin
m xmin mul
sub
def
% x'=mx+b
m mul
b add
}def
/yconv
{
%m=(symax-symin)/(ymax-ymin)
/m
symax symin sub
ymax ymin sub
div
def
%b=(symin-m*ymin)
/b
symin
m ymin mul
sub
def
%y'=my+b
m mul
b add
}def
/conv %stack (top) y x
{
yconv
exch
xconv
exch
} def
/plotline %stack(top) y2 x2 y1 x1 graylevel
{
newpath
conv
moveto
conv
lineto
closepath
setgray
stroke
}def
/square %stack y2 x2 y1 x1 graylevel
{
conv
/y2 exch def
/x2 exch def
conv
/y1 exch def
/x1 exch def
newpath
x1 y1 moveto
x2 y1 lineto
x2 y2 lineto
x1 y2 lineto
x1 y1 lineto
closepath
setgray
stroke
} def
/errorbar % stack size, y x graylevel
{
newpath
% get size into point
% s'=s*(symax-symin)/(ymax-ymin)
symax symin sub
ymax ymin sub
div mul
/size exch def % set size=converted size
conv % convert x&y coods
moveto
0 size rlineto
-10 0 rlineto
20 0 rlineto
-10 0 rlineto
0 size -2 mul rlineto
-10 0 rlineto
20 0 rlineto
setgray
stroke
}def
/point % y x symbol gray
{
/y exch def
/x exch def
/symbol exch def
/gray exch def
/sx x xconv def
/sy y yconv def
%0=blank
symbol 1 eq
{ gray sx 3 sub sy 3 sub sx 3 add sy 3 add squ} if %1= square
symbol 2 eq % 2= circle
{gray sx sy 4 circle} if
symbol 3 eq % 3= up triangle
{ gray sx sy 6 1 tria} if
symbol 4 eq % 4= X
{gray sx sy 4 cross} if
symbol 5 eq % 5= diamond
{gray sx sy 5 diamond} if
symbol 6 eq % 6= down triangle
{ gray sx sy 6 -1 tria} if
symbol 7 eq % 7 =star
{gray sx sy 5 star} if
} def
/diamond %size y x gray
{
newpath
/size exch def
moveto
0 size 2 div rmoveto
size -2 div size -1 mul rlineto
size 2 div size -1 mul rlineto
size 2 div size rlineto
size -2 div size rlineto
setgray
stroke
}def
/cross % size y x gray
{
/size exch def
/y exch def
/x exch def
newpath
x size add y size add moveto
x size sub y size sub lineto
x size sub y size add moveto
x size add y size sub lineto
setgray
stroke
} def
/star % size y x gray
{
/size exch def
/y exch def
/x exch def
newpath
gsave
x y translate
0 15 360
{rotate 0 0 moveto 0 size lineto} for
setgray
stroke
grestore
} def
/tria % updn size y x gray
{
newpath
/updn exch def
/size exch def
moveto
0 size 2 div updn mul rmoveto
size -2 div size -1 mul updn mul rlineto
size 0 rlineto
size -2 div size updn mul rlineto
setgray
stroke
}def
/squ %stack y2 x2 y1 x1 graylevel
{
/y2 exch def
/x2 exch def
/y1 exch def
/x1 exch def
newpath
x1 y1 moveto
x2 y1 lineto
x2 y2 lineto
x1 y2 lineto
x1 y1 lineto
closepath
setgray
stroke
} def
/circle % r y x gray
{
newpath
0 360 arc
setgray
stroke
}def
/grid % stack (top) tky tkx gray
{
initclip
newpath
/tky exch def
/tkx exch def
/gray exch def
/xstep xmax xmin sub tkx div def
/ystep ymax ymin sub tky div def
/i xmin def
[1 3] 0 setdash % make a dotted line
0 1 tkx
{
gray i ymin i ymax plotline
/i i xstep add def % i=i+xstep
} for
/i ymin def
0 1 tky
{
gray xmin i xmax i plotline
/i i ystep add def % i=i+ ystep
} for
[] 0 setdash % back to a solid line
stroke
0.0 xmin ymin xmax ymax square %put a box around the graph
}def
/text % txt pointsize font y x note x,y are in point coordinates!
{
/txt exch def
/pointsize exch def
/font exch def
/y exch def
/x exch def
font findfont
0 setgray
%Helvetic-Bold
%Symbol
%Times-Italic
pointsize
scalefont
setfont
x -1 eq % if x==-1
{ txt stringwidth pop 2 div % get xoffset and divide it by 2
sxmax sxmin sub 2 div sxmin add exch sub
/x exch def % x=(xmax-xmin)/2 + xmin - xoffset
} if
y -1 eq % if y==-1
{
txt stringwidth exch pop 2 div % get yoffset and divide it by 2
symax symin sub 2 div symin add exch sub /y exch def %y=(ymax-ymin)/2+ymin-yoffset
} if
x y moveto
txt show
} def
/vtext % txt pointsize font y x *** x,y are in point coordinates!
{
/txt exch def
/pointsize exch def
findfont
0 setgray
pointsize
scalefont
setfont
/y exch def
/x exch def
x -1 eq % if x==-1
{ txt stringwidth pop 2 div % get xoffset and divide it by 2
sxmax sxmin sub 2 div sxmin add exch sub
/x exch def % x=(xmax-xmin)/2 + xmin - xoffset
} if
y -1 eq % if y==-1
{
txt stringwidth exch pop 2 div % get yoffset and divide it by 2
symax symin sub 2 div symin add exch sub /y exch def %y=(ymax-ymin)/2+ymin-yoffset
} if
x y translate
90 rotate
0 0 moveto
txt show
-90 rotate
x -1 mul y -1 mul translate
} def
/herrorbar % stack size, y x graylevel
{
newpath
% get size into point
% size'=size*(sxmax-sxmin)/(xmax-xmin)
sxmax sxmin sub mul
xmax xmin sub div
/size exch def % set size=converted size
conv % convert x&y coods
moveto
size 0 rlineto
0 -10 rlineto
0 20 rlineto
0 -10 rlineto
size -2 mul 0 rlineto
0 -10 rlineto
0 20 rlineto
setgray
stroke
}def
/doclipping
{
%setup clipping
newpath
sxmin symin moveto
sxmax symin lineto
sxmax symax lineto
sxmin symax lineto
sxmin symin lineto
clip
}def
/polynom % stack (top) max min N a[n-1] ... a[0] gray
{
/max exch def
/min exch def
/N exch def
/coeff N array def % coefficints array size of N
newpath
N 1 sub
{
/index exch def
index coeff % move a[i] before i on stack
3 1 roll % stack (top) a[j] i array
exch
put % put into array
index 0 le % exit if i<=0
{exit} if
index 1 sub % i-1
} loop
%step= (max-min)/(sxmax-sxmin)
/step max min sub sxmax sxmin sub div def
% x=min to max
min
{
/x exch def
/y 0 def
%do j=0 to n-1
0
{
/j exch def
/y x j power coeff j get mul y add def % y += x^j * a[j]
j N 1 sub ge % if j >= N-1 exit
{exit} if
j 1 add
} loop
% if x=min moveto else lineto...
x y
conv
x min eq % x==min
{moveto } { lineto} ifelse
%
%
%
x max ge % if x>= max exit
{ exit} if
x step add
} loop
%closepath
setgray
stroke
}def
/power %(args) n x
{
/n exch def
/x exch def
/ret 1.0 def
1 % i=1 while i< n
{
/in exch def
/ret ret x mul def % ret *= x;
in n ge % i>=n
{exit} if
in 1 add
}loop
n 1 eq
{ /ret x def } if
n 0 eq
{/ret 1.0 def} if
ret
}def
doclipping % set up clipping