ヒルベルト曲線(アニメーション)

 投稿者:hayashi  投稿日:2019年 1月16日(水)16時06分10秒
  REM ヒルベルト曲線(アニメーション)
OPTION ANGLE DEGREES
LET LEFT   = 0
LET RIGHT  = 2
LET BOTTOM = 0
LET TOP    = 2
SET WINDOW LEFT, RIGHT, BOTTOM, TOP
SET LINE COLOR 6 ! 黄
DO
   FOR N = 1 TO 6
      SET DRAW MODE HIDDEN    ! 描画途中を画面に反映させない
      SET AREA COLOR 1        ! 背景を黒で塗りつぶす
      PLOT AREA : LEFT,BOTTOM;RIGHT,BOTTOM;RIGHT,TOP;LEFT,TOP
      LET DIRECTION = 0
      LET CURX = 0.5
      LET CURY = 0.5
      LET L = 1
      DRAW HIRBERT(N, L, 90) WITH SCALE(0.5^(N-1))
      SET DRAW MODE EXPLICIT  ! 描画結果を画面に反映させる
      WAIT DELAY 1            ! 処理を1秒停止
   NEXT N
LOOP

PICTURE FORWARD(R)
   LET X0 = CURX
   LET Y0 = CURY
   LET CURX = CURX + R*COS(DIRECTION)
   LET CURY = CURY + R*SIN(DIRECTION)
   PLOT LINES: X0, Y0; CURX, CURY
END PICTURE

SUB TURN(T)
   LET DIRECTION = DIRECTION + T
END SUB

PICTURE HIRBERT(N, L, A)
   IF N <> 0 THEN
      CALL TURN( A)
      DRAW HIRBERT(N - 1, L, -A)
      DRAW FORWARD(L)
      CALL TURN(-A)
      DRAW HIRBERT(N - 1, L,  A)
      DRAW FORWARD(L)
      DRAW HIRBERT(N - 1, L,  A)
      CALL TURN(-A)
      DRAW FORWARD(L)
      DRAW HIRBERT(N - 1, L, -A)
      CALL TURN( A)
   END IF
END PICTURE
END
 

戻る