5 '** GENDRAGN ** Written by Dan Rollins 4/29/82 ** 6 '** as published in BYTE, December 1983 ** re-done for CP/M MBASIC by Bob Bloom ** 7 '** Creates a "generalized" or "classical" Dragon curve. ** use with DISKPLOT subroutines or modify for high-res video plotting. ** 10 CLEAR 25000 :DEFINT A-Z '** clear less if out of memory 15 CS$=CHR$(12) '** define clear screen 20 REM clear screen and opening message 25 PRINT CS$ :PRINT "Generalized dragon curve generator" 30 PRINT "programmed by Dan Rollins as published in BYTE, Dec 83" 35 PRINT "adapted for CP/M's MBASIC by Bob Bloom" :PRINT :PRINT 40 PRINT "Create a (N)ew plot, (P)rint an pre-existing file or" 45 INPUT "'X' to exit program (N/P/X)";PQ$ 50 IF PQ$="P" THEN GOSUB 5000 :GOTO 10 55 IF PQ$="X" THEN STOP ELSE IF PQ$<>"N" GOTO 40 60 PRINT :INPUT "Input order (# folds) of dragon curve";N 65 PRINT :PRINT "Input the direction folding sequence as a string of" 70 PRINT "L's and R's ... i.e. LLRRLRRR. Enter a 'G' to generate a" 80 PRINT "random sequence. Enter a single 'L' for the classical dragon" 100 INPUT LR$ :IF LR$<>"G" THEN 140 110 RANDOMIZE :LR$="" :FOR J=1 TO N 120 IF RND+.5>1 THEN LR$=LR$+"L" ELSE LR$=LR$+"R" 130 NEXT :PRINT :PRINT "random direction reversal sequence: ";LR$ 140 L=LEN(LR$) :LAST=2^N-1 :DIM D(LAST+1) 170 PRINT :PRINT "** generating the dragon sequence **" :PRINT 180 SP=1 :IP=1 :IF LEFT$(LR$,1)="L" THEN D(1)=1 ELSE D(1)=-1 190 FOR J=2 TO N 200 IP=IP+1 :IF IP>L THEN IP=1 210 IF MID$(LR$,IP,1)="L" THEN IN=1 ELSE IN=-1 220 D(SP+1)=IN '** add DRS fold 230 FOR K=1 TO SP 240 D(2*SP+2-K)=-D(K) '** invert prior folds 250 NEXT 260 SP=SP*2+1 270 NEXT 280 DX(2)=1 :DX(4)=-1 :DY(1)=-1 :DY(3)=1 284 INPUT "length of dragon segments (scale factor 1 to ??)";SC 286 IF SC<1 GOTO 150 :PRINT 288 INPUT "automatically center dragon curve (Y/N)";QA$ 290 IF QA$="Y" GOTO 320 300 INPUT "starting point (X,Y)";SX,SY :INPUT "starting direction: (1=North, 2=West, 3=South, 4=East)";SD 310 IF SX<0 OR SY<0 OR SD<1 OR SD>4 THEN 300 ELSE 460 320 SD=1 '** initial DIRECTION vector 325 XH=-1 :XL=1 :YH=-1 :YL=1 :SX=0 :SY=0 330 PRINT :PRINT "** Centering **" :PRINT :X=SX :Y=SY :D=SD 340 FOR J=1 TO LAST 350 X=X+DX(D) :Y=Y+DY(D) 360 IF XXH THEN XH=X 370 IF YYH THEN YH=Y 380 D=D-D(J) :IF D<1 THEN D=4 ELSE IF D>4 THEN D=1 390 NEXT 400 XH=XH*(4+SC) :XL=XL*(4+SC) :YL=YL*(4+SC) :YH=YH*(4+SC) 410 XD=XH-XL :YD=YH-YL :SX=SX-XL :SY=SY-YL 420 PRINT USING "Starting point X=### Y=### Starting Direction = ##";SX,SY,SD 425 PRINT USING "Plot will be ### dots wide and ### dots long";XD,YD 426 PRINT "While using segment length of";SC 430 INPUT "Is this OK (Y/N)";QA$ :IF QA$="Y" GOTO 460 ELSE IF QA$<>"N" GOTO 430 435 INPUT "NEW Starting Direction to use";SD 440 INPUT "NEW segment length to use";SC :GOTO 325 450 '** ** the following code interprets the dragon sequence, ** plotting the folds ** 460 P12=7 :P10=XD :P9=YD '** parms for gosub 461 GOSUB 3000 :X=SX :Y=SY :D=SD :PRINT CS$ 462 GOSUB 1500 'plot starting dot 470 FOR J=1 TO LAST 480 FOR K=1 TO SC 490 X=X+DX(D) :Y=Y+DY(D) :GOSUB 1500 '** plot X,Y 500 NEXT 510 D1=D :D=D-D(J) :IF D<1 THEN D=4 ELSE IF D>4 THEN D=1 530 FOR K=1 TO 2 540 X=X+DX(D1)+DX(D) :Y=Y+DY(D1)+DY(D) 550 GOSUB 1500 '** plot X,Y 560 NEXT 570 PRINT CP4$; :PRINT USING "remaining folds to plot: ####";LAST-J 580 NEXT 590 PRINT CHR$(7) :GOSUB 4000 '** close the file 600 GOSUB 5000 '** print the file 610 LPRINT 620 LPRINT TAB(34);"Order ";N;" Dragon Curve" 630 LPRINT TAB(22-L/2);"Direction Reversal Sequence: ";LR$;" Segment Size: ";SC 640 IF L=1 THEN LPRINT TAB(30)"... Classical Dragon Curve" 670 GOTO 10