home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / diskplot / diskplot.lbr / GENDRAGN.BQS / GENDRAGN.BAS
Encoding:
BASIC Source File  |  1985-06-17  |  3.9 KB  |  90 lines

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