home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
ZSYS
/
ZNODE-12
/
I
/
MXPLOT.LBR
/
DRAGON.PZS
/
DRAGON.PAS
Wrap
Pascal/Delphi Source File
|
1991-10-03
|
5KB
|
154 lines
program dragon;
{ Author: Larry Schnitger, co-Sysop, Zitel BBS, 617 965-7046 }
const
maxdot = 575; { highest x or y value FXPLOT allows }
{ when using the 72 dpi mode }
var
folds : array[1..8191] of char; { space for order 13: 2^13-1=8191 }
dx, dy : array[0..3] of integer;
xmax, xmin, xend, ymax, ymin, yend : integer;
order, numf : integer;
d0, x0, y0 : integer;
range, side, str, corner : integer;
pfile : text; { plot file read by FXPLOT }
{--------------------------------------------------------------------------}
procedure calcfolds( n : integer; var last : integer );
var
f, i : integer;
begin
last:=0; { initialize last calculated fold }
for f:=1 to n do { iteratively calculate fold sequence }
begin
folds[last+1]:='L'; { insert next fold (all are L for dragon) }
{ if not odd(f) then folds[last+1]:='R'; }
{ un-comment the statement above }
{ to alternate folds }
{ (LRLR...) a very surprising }
{ result!! }
for i:=1 to last do { next piece is same as first... }
folds[last+1+i]:=folds[i];
if (last>0) and { ...except reverse middle fold }
(folds[last+1 + (last+1) div 2]='L')
then folds[last+1 + (last+1) div 2]:='R'
else folds[last+1 + (last+1) div 2]:='L';
last:=2*last+1 { update last fold value }
end
end; {calcfolds}
{--------------------------------------------------------------------------}
procedure limits( d, numfold : integer);
var
i : integer;
begin
xmin:=0; xmax:=0; ymin:=0; ymax:=0; { get set to find size of result }
xend:=dx[d]; yend:=dy[d];
if xend<0 then xmin:=xend else xmax:=xend;
if yend<0 then ymin:=yend else ymax:=yend;
for i:=1 to numfold do { for each fold in the strip }
begin
if folds[i]='L'
then d:=(d+1) mod 4 { turn clockwise or }
else d:=(d+3) mod 4; { turn counter-clockwise }
xend:=xend+dx[d]; yend:=yend+dy[d]; { add length in proper direction }
if xend>xmax then xmax:=xend; { update max/min values }
if xend<xmin then xmin:=xend;
if yend>ymax then ymax:=yend;
if yend<ymin then ymin:=yend
end;
write( 'order ', order:2, ': ' );
write( 'endpoint = (', xend, ', ', yend, '), ' );
write( 'x ranges ', xmin, ' to ', xmax, ', ');
writeln( 'y ranges ', ymin, ' to ', ymax, '.' )
end; {limits}
{--------------------------------------------------------------------------}
procedure plotfile( x, y, d, st, cr, n : integer);
var
i, j, dold : integer;
begin
write( 'plotting: ', 'x0 = ', x:3, ' y0 = ', y:3, ' d0 = ', d );
writeln( ' side = ', st+2*cr:3, ' strt = ', st:2, ' crnr = ', cr:2 );
{ draw initial segment. V draws a vector, needs (x1,y1) & (x2,y2) }
x:=x+cr*dx[d]; y:=y+cr*dy[d]; { (x1,y1) }
write(pfile, 'V', chr(hi(x)), chr(lo(x)), chr(hi(y)), chr(lo(y)) );
x:=x+st*dx[d]; y:=y+st*dy[d]; { (x2,y2) }
write(pfile, chr(hi(x)), chr(lo(x)), chr(hi(y)), chr(lo(y)) );
for i:=1 to n do { for each fold... }
begin
dold:=d; { previous direction }
if folds[i]='L' { calc. new direction }
then d:=(d+1) mod 4 { turn c-wise or }
else d:=(d+3) mod 4; { turn c-c-wise }
{ draw a corner by plotting individual points. P plots point (x,y) }
{ (done this way because fxplot does crummy angles) }
for j:=1 to cr do
begin
x:=x+dx[dold]+dx[d]; y:=y+dy[dold]+dy[d]; { does a 45 deg corner }
write(pfile, 'P', chr(hi(x)), chr(lo(x)), chr(hi(y)), chr(lo(y)) )
end;
{ draw next segment. R draws line from previous position to (x,y) }
x:=x+dx[d]*st; y:=y+dy[d]*st;
write(pfile, 'R', chr(hi(x)), chr(lo(x)), chr(hi(y)), chr(lo(y)) )
end
end; {plotfile}
{---------------------------------------------------------------------------}
begin {dragon}
repeat
writeln;
write('What order dragon to plot? (1 to 13) ');
readln(order);
until (order<=13) and (order>0);
writeln;
d0:=0; { default starting direction }
repeat
write('what direction to start? (0 to 3): ');
readln(d0);
until (d0>=0) and (d0<=3);
dx[0]:= 1; dy[0]:= 0; { 0 } { offsets for various directions }
dx[1]:= 0; dy[1]:= 1; { 90 }
dx[2]:=-1; dy[2]:= 0; { 180 }
dx[3]:= 0; dy[3]:=-1; { 270 }
calcfolds(order, numf); { figure sequence of folds }
limits(d0, numf); { figure min's, max's, end point }
{$I DRAGN-1.INC }
{ ** change include file to ** }
{ ** D4-HEADS.INC or D4-TAILS.INC for 4 dragon plot ** }
end. {dragon}