home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
qtawk
/
sincos.exp
< prev
next >
Wrap
Text File
|
1990-02-10
|
3KB
|
110 lines
# greph - processor for a graph-drawing language
# input: data and specification of a graph
# output: data plotted in specified area
# AWK page 137
#
# display sine and cosine curves - no input accepted
BEGIN { #set frame dimensions ...
OFMT = "%.4g";
ht = 23; wid = 79; # height and width
ox = 6; oy = 2; # offset for x and y axes
xmin = 0;
xmax = 2*pi;
ymin = -1.25;
ymax = 1.25;
x_inc = pi/200;
pi2 = 2*pi;
for ( x = 0.0 ; x <= pi2 ; x += x_inc ) {
xs = xscale(x);
plot(xs,yscale(sin(x)),'s');
plot(xs,yscale(cos(x)),'c');
}
botlab = "Sine/Cosine Curves";
nl = 9;
nb = 8;
lticks[9] = 1.;
lticks[8] = .75;
lticks[7] = .5;
lticks[6] = .25;
lticks[5] = 0.0;
lticks[4] = -.25;
lticks[3] = -.5;
lticks[2] = -.75;
lticks[1] = -1.;
bticks[8] = 7*pi/4;
bticks[7] = 3*pi/2;
bticks[6] = 5*pi/4;
bticks[5] = pi;
bticks[4] = 3*pi/4;
bticks[3] = pi/2;
bticks[2] = pi/4;
bticks[1] = 0.0;
frame; ticks; label; data; draw;
}
function frame() { # create frame for graph
local i, j;
for ( i = ox+1 ; i < wid ; i++ ) plot(i,oy,"─"); # bottom
for ( i = ox+1 ; i < wid ; i++ ) plot(i,ht-1,"─"); # top
for ( i = oy+1 ; i < ht ; i++ ) plot(ox,i,"│"); # left
for ( i = oy+1 ; i < ht ; i++ ) plot(wid-1,i,"│"); # right
plot(ox,ht-1,"┌");
plot(wid-1,ht-1,"┐");
plot(ox,oy,"└");
plot(wid-1,oy,"┘");
}
function ticks() { # create tick marks for both axes
local i;
local xys;
for ( i = 1 ; i <= nb ; i++ ) {
xys = xscale(bticks[i]);
plot(xys,oy,"┼");
splot(xys - 1,1,bticks[i]);
}
for ( i = 1 ; i <= nl ; i++ ) {
xys = yscale(lticks[i]);
plot(ox,xys,"┼");
splot(0,xys,lticks[i]);
}
}
function label() { # center label under x-axis
splot((wid + ox - length(botlab))/2,0,botlab);
}
function draw() { # print graph from array
local i, j;
for ( i = ht - 1 ; i >= 0 ; i-- ) {
for ( j = 0 ; j < wid ; j++ )
printf( j in array && i in array[j] ? array[j][i] : " " );
printf("\n");
}
}
function xscale(x) { # scale x-value
return int((x - xmin + 0.0)/(xmax - xmin) * (wid - 1.0 - ox) + ox + 0.5);
}
function yscale(y) { # scale y-value
return int((y - ymin + 0.0)/(ymax - ymin) * (ht - 1.0 - oy) + oy + 0.5);
}
function plot(x,y,c) { # put character c in array
array[x][y] = c;
}
function splot(x,y,s) { # put string s in array
local i, n = length(s);
local str = s "";
for ( i = 0 ; i < n ; i++ )
array[x+i][y] = substr(str,i+1,1);
}