S.9 Binary Tree-2

目次のページ; 前のページ; 次のページ

 この例題2は例題1と同じ2分岐木構造のプログラムで、再帰処理の例題です。こちらの作図はメタファイルへの書き出しができます

Public Sub Proc9()
    Dim n, m, i, j, x, y, Th, angle
    Select Case Ivar
        Case 1: n = 3
        Case 2: n = 4
        Case 3: n = 5
        Case 4: n = 6
        Case Else: n = 3
    End Select
    Dperas
    Dpwind 0, 0, 640
    angle = pie / n
    x = 0
    y = 150
    lenn = LENGTH
    Th = pie / 2
    Dpmove x, YSIZE
    Dpdraw x, (YSIZE - y)
    Tree x, y, lenn, Th, angle
End Sub
'--------------------------------------------------------------
Private Sub Tree(x, y, ByVal lenn, Th, angle)
    Dim x1, x2, y1, y2, th1, th2
    If lenn <= LENGTH / 15 Then Exit Sub
    lenn = lenn * 0.75
    th1 = Th - angle
    th2 = Th + angle
    x1 = x + lenn * Cos(th1)
    y1 = y + lenn * Sin(th1)
    x2 = x + lenn * Cos(th2)
    y2 = y + lenn * Sin(th2)
    Dpmove x, (YSIZE - y)
    Dpdraw x1, (YSIZE - y1)
    Tree x1, y1, lenn, th1, angle
    Dpmove x, (YSIZE - y)
    Dpdraw x2, (YSIZE - y2)
    Tree x2, y2, lenn, th2, angle
End Sub

次のページ