      PROGRAM koch
*     再帰的方法を用いて3次コッホ曲線を生成する
*    
      IMPLICIT NONE
      REAL*8 x1, x2, y1, y2
      INTEGER IR_, n, k
      LOGICAL TBkeyinput
      DATA k/0/
      CALL GWopen(IR_, 0)
      CALL initial(x1,y1,x2,y2,n)
*     異なる反復数のコッホ曲線を描く
      DO WHILE(k .NE. ICHAR('s'))
         k = 0
         CALL draw(x1,y1,x2,y2,n)
         DO WHILE(.NOT. TBkeyinput())
         ENDDO
         CALL TBgetkey(k)
         n = n + 1                          ! 世代数
         CALL GWclear(IR_, -1)
      END DO
      CALL GWquit(IR_)
      END
C
      SUBROUTINE initial(x1,y1,x2,y2,n)
      IMPLICIT NONE
      REAL*8 x1, y1, x2, y2
      REAL xwin, ywin
      INTEGER IR_, n
      n = 0                                 ! 反復数
      x1 = 1                                ! 線分の左の端の座標
      y1 = 5                                ! 単位は任意
      x2 = 10                               ! 線分の右の端の座標
      y2 = 5
      CALL compute_aspect_ratio(8.0,xwin,ywin)
      CALL GWindow(IR_, 0.0, 0.0, xwin, ywin)
      CALL GWsetpen(IR_, 16, -1, -1, -1)
      END
