C曲線

 投稿者:しばっち  投稿日:2017年 5月27日(土)09時48分17秒
  OPTION BASE 0
PUBLIC NUMERIC X,Y,ALPHA,KK,XX(8500),YY(8500)
DIM FR(8500),FI(8500),TX(8500),TY(8500)
CALL GINIT(800,600)
LET N=10
LET L=400
CALL JUMP(200,450)
CALL RECURSIVE(N,L)
LET LV=INT(LOG2(KK))+1
MAT TX=XX
MAT TY=YY
DO
   MAT XX=TX
   MAT YY=TY
   FOR I=1 TO KK-1
      LET FR(I+1)=XX(I+1)-XX(I)
      LET FI(I+1)=YY(I+1)-YY(I)
   NEXT I
   CALL FFT(LV,FR,FI,1)
   LOCATE VALUE ,RANGE 2 TO 2^(LV-1)-1:NCUT
   LET NCUT=INT(NCUT)
   FOR I=NCUT+1 TO 2^LV-NCUT-1
      LET FR(I)=0
      LET FI(I)=0
   NEXT I
   CALL FFT(LV,FR,FI,-1)
   CLEAR
   PLOT LINES
   FOR I=1 TO KK
      LET XX(I+1)=XX(I)+FR(I+1)
      LET YY(I+1)=YY(I)+FI(I+1)
      IF I=1 THEN PLOT LINES:XX(I),YY(I);
      PLOT LINES:XX(I+1),YY(I+1);
   NEXT I
LOOP
END

EXTERNAL SUB RECURSIVE(LEV,L)
IF LEV=0 THEN
   CALL MOVE(L)
ELSE
   CALL TURN(45)
   CALL RECURSIVE(LEV-1,L/SQR(2))
   CALL TURN(-90)
   CALL RECURSIVE(LEV-1,L/SQR(2))
   CALL TURN(45)
END IF
END SUB

EXTERNAL SUB GINIT(XSIZE,YSIZE)
SET BITMAP SIZE XSIZE,YSIZE
SET WINDOW 0,XSIZE-1,YSIZE-1,0
SET POINT STYLE 1
SET COLOR MODE "REGULAR"
SET COLOR MIX(0) 0,0,0
SET COLOR MIX(1) 0,0,1
SET COLOR MIX(2) 1,0,0
SET COLOR MIX(3) 1,0,1
SET COLOR MIX(4) 0,1,0
SET COLOR MIX(5) 0,1,1
SET COLOR MIX(6) 1,1,0
SET COLOR MIX(7) 1,1,1
CLEAR
SET COLOR 7
END SUB

EXTERNAL SUB MOVE(L)
LET X=X+L*COS(ALPHA*PI/180)
LET Y=Y-L*SIN(ALPHA*PI/180)
PLOT LINES:X,Y;
LET KK=KK+1
LET XX(KK)=X
LET YY(KK)=Y
END SUB

EXTERNAL SUB TURN(R)
LET ALPHA=MOD(ALPHA+R+360,360)
END SUB

EXTERNAL SUB JUMP(XA,YA)
LET X=XA
LET Y=YA
PLOT LINES:X,Y;
LET KK=KK+1
LET XX(KK)=X
LET YY(KK)=Y
END SUB

EXTERNAL SUB FFT(M,XR(),XI(),INVERSE)
LET N=2^M
LET L=N/2
LET J=L+1
FOR I=2 TO N-2
   IF I<J THEN
      SWAP XR(I),XR(J)
      SWAP XI(I),XI(J)
   END IF
   LET K=L
   DO WHILE K<J
      LET J=J-K
      LET K=K/2
   LOOP
   LET J=J+K
NEXT I
IF INVERSE=1 THEN
   LET PX=-PI
ELSE
   FOR I=1 TO N
      LET XR(I)=XR(I)/N
      LET XI(I)=XI(I)/N
   NEXT I
   LET PX=PI
END IF
LET L=1
FOR K=1 TO M
   LET LL=L+L
   LET P=PX/L
   FOR J=1 TO L
      LET W=(J-1)*P
      LET WR=COS(W)
      LET WI=SIN(W)
      FOR I=J TO N STEP LL
         LET IL=I+L
         LET TR=XR(IL)*WR-XI(IL)*WI
         LET TI=XR(IL)*WI+XI(IL)*WR
         LET XR(IL)=XR(I)-TR
         LET XI(IL)=XI(I)-TI
         LET XR(I)=XR(I)+TR
         LET XI(I)=XI(I)+TI
      NEXT I
   NEXT J
   LET L=LL
NEXT K
END SUB
 

戻る