再帰図形ジェネレータ

 投稿者:しばっち  投稿日:2012年12月16日(日)14時48分15秒
  PUBLIC NUMERIC NN,XX,YY,RR,X(20),Y(20),L(20),R(20),S(20)
LET MODE=0
SELECT CASE MODE
CASE 0
   RESTORE 1 !'この行番号を直接書き換えてください
   READ NN
   FOR I=1 TO NN
      READ X(I),Y(I) !'座標データ 始点(0,0)から終点(1,0)へ
   NEXT I
   READ XS,XE,YS,YE  !'WINDOW設定
   FOR I=1 TO NN-1
      READ S(I) !'符号反転(1 or -1)
   NEXT I
1    DATA 5
     DATA 0,0, .333333,0, .5,.288675134594813, .666666,0, 1,0 !'コッホ曲線
     DATA -.1,1.1,-.6,.6
     !'DATA 1,1,1,1
     DATA 1,-1,1,-1   !'変形コッホ
     !'DATA 1,-1,-1,1 !'変形コッホ
     !'DATA 1,1,-1,-1 !'変形コッホ
     !'----------------------------------------------------------
2    DATA 3
     DATA 0,0,.5,.5,1,0 !'C曲線
     DATA -.5,1.5,-1,1
     DATA 1,1 !'C曲線
     !'DATA 1,-1 !'ドラゴン曲線
     !'----------------------------------------------------------
3    DATA 6
     DATA 0,0, .33333,0, .33333,.33333, .66666,.33333, .66666,0, 1,0
     DATA -.1,1.1,-.6,.6
     !'DATA 1,1,1,1,1
     DATA 1,-1,1,-1,1
     !'DATA 1,1,-1,1,1
     !'----------------------------------------------------------
4    DATA 8
     DATA 0,0, .25,0, .25,.25, .5,.25, .5,-.25,.75,-.25,.75,0, 1,0
     DATA -.1,1.1,-.6,.6
     DATA 1,1,1,1,1,1,1
     !'----------------------------------------------------------
5    DATA 5
     DATA 0,0,.26500453458963,0,.3,.4, .33499546541037,0,1,0 !'森
     DATA -.1,1.1,-.6,.6
     DATA 1,1,1,1
     !'----------------------------------------------------------
6    DATA 7
     DATA 0,0,.2,0,.2,.2,.4,.2,.4,-.2,.8,-.2,1,0 !'さんご礁
     DATA -.1,1.1,-.6,.6
     DATA 1,1,1,1,1,1
     !'----------------------------------------------------------
7    DATA 6
     DATA 0,0,.12,0,.12,.2078,.53,.2078,.53,0,1,0 !'ひび割れた岩?
     DATA -.1,1.1,-.6,.6
     DATA 1,1,1,1,1
     !'----------------------------------------------------------
8    DATA 13
     DATA 0,0,.1870534607777,0,.319320231338024,-.132266770560324,.5,-.18067976866193,.680679768661883,-.132266770560324,.812946539222206,0,.680679768661883,.132266770560324,.5,.18067976866193,.319320231338023,.132266770560324,.451587001898347,0,.632266770560277,-4.84129981016061E-2,.812946539222206,0,1,0
     DATA -.1,1.1,-.6,.6
     DATA 1,1,1,1,1,1,1,1,1,1,1,1
     !'----------------------------------------------------------
9    DATA 5
     DATA 0,0,.5,0,.5,.3333333,.5,0,1,0
     DATA -.1,1.1,-.6,.6
     DATA 1,1,1,1
     !'----------------------------------------------------------
10    DATA 4
      DATA 0,0,.25,.433012,.75,.433012,1,0
      DATA -.5,1.5,-1,1
      DATA 1,1,1
      !'----------------------------------------------------------
11    DATA 10
      DATA  0,0,0 ,-.2928932188 , .103553390588518 ,-.396446609388518 , .396446609388518 ,-.396446609388518 , .5 ,-.2928932188 , .5, .2928932188 , .603553390565553 , .396446609388518 , .896446609365553 , .396446609388518 ,1,.2928932188,1,0
      DATA -.5,1.5,-1,1
      DATA 1,1,1,1,1,1,1,1,1,1
      !'----------------------------------------------------------
12    DATA 7
      DATA 0,0,.292893218813,0, .292893218813 ,.292893218813 , .5 ,8.57864376267724E-2 , .707106781185455 ,.292893218813 , .707106781185455 , 0 , 1,0
      DATA -.1,1.1,-.6,.6
      DATA 1,1,1,1,1,1
      !'----------------------------------------------------------
13    DATA 9
      DATA 0,0, .211324865405187 , 0 , .394337567297406 ,.105662432702593 , .5 ,.288675134594813 , .5 ,.5 , .5 ,.288675134594813 , .605662432702593 ,.105662432702593 , .788675134594812 , 0 , 1, 0
      DATA -.1,1.1,-.6,.6
      DATA 1,1,1,1,1,1,1,1
      !'----------------------------------------------------------
      !'ここにDATA文を追加してください
      !'----------------------------------------------------------
   CASE 1 !'乱数によりデータ生成
      RANDOMIZE
      LET NN=INT(RND*4)+3
      LET X(1)=0 !'始点
      LET Y(1)=0
      LET S(1)=1-INT(RND*2)*2
      FOR I=2 TO NN-1
         LET X(I)=RND
         LET Y(I)=RND-.4
         LET S(I)=1-INT(RND*2)*2
      NEXT I
      LET X(NN)=1 !'終点
      LET Y(NN)=0
      LET XS=-.5  !'WINDOW設定
      LET XE=1.5
      LET YS=-1
      LET YE=1
      PRINT "DATA";NN !'このDATA文を「ここに..」に追加してください
      PRINT "DATA";
      FOR I=1 TO NN-1
         PRINT X(I);",";Y(I);",";
      NEXT I
      PRINT X(NN);",";Y(NN)
      PRINT "DATA ";XS;",";XE;",";YS;",";YE
      PRINT "DATA ";
      FOR I=1 TO NN-2
         PRINT S(I);",";
      NEXT I
      PRINT S(NN-1)
   END SELECT
   FOR I=1 TO NN-1
      LET R(I)=ANGLE(X(I+1)-X(I),Y(I+1)-Y(I))-RR
      LET RR=RR+R(I)
      LET L(I)=SQR((X(I)-X(I+1))^2+(Y(I+1)-Y(I))^2)
   NEXT I
   IF MOD(RR,2*PI)<>0 THEN LET R(NN)=-RR
   SET WINDOW  XS,XE,YE,YS
   SET POINT STYLE  1
   SET COLOR MODE "REGULAR"
   FOR N=2 TO 6
      CLEAR
      DRAW GRID(.1,.1)
      LET RR=0
      LET XX=0
      LET YY=0
      CALL RECURSIVE(N,1,1)
      WAIT DELAY 1
   NEXT N
END

EXTERNAL  SUB RECURSIVE(N,LL,SIGN)
   IF N=0 THEN
      PLOT LINES: XX,YY;
      LET XX=XX+LL*COS(RR)
      LET YY=YY-LL*SIN(RR)
      PLOT LINES: XX,YY
   ELSE
      FOR I=1 TO NN-1
         LET RR=RR+R(I)*SIGN
         CALL RECURSIVE(N-1,LL*L(I),S(I))
      NEXT I
      IF R(NN)<>0 THEN LET RR=RR+R(NN)*SIGN
   END IF
END SUB
 

戻る