Category : Miscellaneous Language Source Code
Archive   : QTAWKU42.ZIP
Filename : SINCOS.EXP

 
Output of file : SINCOS.EXP contained in archive : QTAWKU42.ZIP
# 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);
}


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : QTAWKU42.ZIP
Filename : SINCOS.EXP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/