|
マウスで3ヶ所以上を左クリックした後に右クリックすると
再帰図形を描画します(level 5まで)
PUBLIC NUMERIC NN,XX,YY,RR,X(40),Y(40),L(40),R(40),S(40),R0,L0,SMIN,SMAX
OPTION ANGLE DEGREES
LET XS=-.5
LET XE=1.5
LET YS=-.5
LET YE=1.5
LET SMIN=10000000
LET SMAX=-SMIN
MAT S=(1)*CON
ASK BITMAP SIZE XSIZE,YSIZE
SET WINDOW XS,XE,YS,YE
SET COLOR MODE "REGULAR"
CLEAR
DRAW GRID(.1,.1)
SET LINE COLOR 1
DO
MOUSE POLL XX,YY,LEFT,RIGHT
IF RIGHT<>0 THEN
IF NN>2 THEN EXIT DO !'3ヶ所以上で右クリック
END IF
IF LEFT<>0 THEN
DO WHILE LEFT<>0
MOUSE POLL XX,YY,LEFT,RIGHT
LOOP
LET NN=NN+1 !'座標値を記録
LET X(NN)=XX
LET Y(NN)=YY
PLOT LINES:XX,YY;
CALL CIRCLEFULL(X(NN),Y(NN),.01,1)
END IF
LOOP
PLOT LINES:X(NN),Y(NN)
CALL CIRCLEFULL(X(NN),Y(NN),.01,1)
LET R0=ANGLE(X(NN)-X(1),Y(NN)-Y(1))
LET L0=1/SQR((X(NN)-X(1))^2+(Y(NN)-Y(1))^2)
FOR I=1 TO NN-1
LET R(I)=ANGLE(X(I+1)-X(I),Y(I+1)-Y(I))-RR-R0
LET RR=RR+R(I)
LET L(I)=SQR((X(I)-X(I+1))^2+(Y(I+1)-Y(I))^2)*L0
NEXT I
IF RR<>0 THEN LET R(NN)=-RR
FOR N=1 TO 5 !'レベル5まで
CLEAR
LET RR=0
LET XX=X(1)
LET YY=Y(1)
DRAW GRID(.1,.1)
CALL RECURSIVE(N,1) !'再帰呼び出し
WAIT DELAY 1
NEXT N
PRINT "OPTION ANGLE DEGREES"
PRINT "PUBLIC NUMERIC X,Y,R"
PRINT "SET WINDOW ";SMIN;",";SMAX;",";SMIN;",";SMAX
PRINT "SET COLOR MODE ";CHR$(34);"REGULAR";CHR$(34)
PRINT "DRAW GRID(.1,.1)"
PRINT "INPUT PROMPT ";CHR$(34);"LEVEL=";CHR$(34);": N"
PRINT "LET X=";STR$(X(1))
PRINT "LET Y=";STR$(Y(1))
PRINT "CALL RECURSIVE(N,1,1)"
PRINT "END"
PRINT
PRINT "EXTERNAL SUB RECURSIVE(LEV,L,SIGN)"
PRINT "OPTION ANGLE DEGREES"
PRINT "IF LEV=0 THEN"
PRINT "PLOT LINES: X,Y;"
PRINT "LET X=X+L*COS(R";VSTR$(R0);")/";STR$(L0)
PRINT "LET Y=Y+L*SIN(R";VSTR$(R0);")/";STR$(L0)
PRINT "PLOT LINES: X,Y"
PRINT "ELSE"
FOR I=1 TO NN-1
IF R(I)<>0 THEN
IF R(I)>0 THEN PRINT "R=R+";ELSE PRINT "R=R-";
PRINT STR$(ABS(R(I)));"*SIGN"
END IF
PRINT "CALL RECURSIVE(LEV-1,L*";STR$(L(I));",";STR$(S(I));")"
NEXT I
IF R(NN)<>0 THEN
IF R(NN)>0 THEN PRINT "R=R+";ELSE PRINT "R=R-";
PRINT STR$(ABS(R(NN)));"*SIGN"
END IF
PRINT "END IF"
PRINT "END SUB"
END
EXTERNAL SUB RECURSIVE(N,LL)
OPTION ANGLE DEGREES
IF N=0 THEN
PLOT LINES:XX,YY;
LET XX=XX+LL*COS(RR+R0)/L0
LET YY=YY+LL*SIN(RR+R0)/L0
PLOT LINES:XX,YY
LET SMIN=MIN(SMIN,XX)
LET SMAX=MAX(SMAX,XX)
LET SMIN=MIN(SMIN,YY)
LET SMAX=MAX(SMAX,YY)
ELSE
FOR I=1 TO NN-1
LET RR=RR+R(I)
CALL RECURSIVE(N-1,LL*L(I))
NEXT I
IF R(NN)<>0 THEN LET RR=RR+R(NN)
END IF
END SUB
EXTERNAL SUB CIRCLEFULL(X,Y,RR,C)
SET COLOR C
DRAW DISK WITH SCALE(RR)*SHIFT(X,Y)
END SUB
EXTERNAL FUNCTION VSTR$(N)
IF N<0 THEN LET S$="-" ELSE LET S$="+"
LET VSTR$=S$ & STR$(ABS(N))
END FUNCTION
|
|