そういえばというわけで、AB5のプロンプト画面でも書くわけです。もしかしたら、この調子で、ABでGDIとかGDI+とかDirect2Dとかやるかもしれません。

#prompt

Imports ActiveBasic.Math

Sub DrawKochCurveAB(startX As Double, startY As Double, endX As Double, endY As Double, level As Long)
    Dim dx = endX - startX
    Dim dy = endY - startY
    Dim trisectionLengthX = dx / 3.0
    Dim trisectionLengthY = dy / 3.0
    Dim triangleHeight = Hypot(trisectionLengthX, trisectionLengthY) * 0.5 * Sqr(3.0)
    Dim angle = Atan2(dy, dx)
    Dim vertexX = startX + dx * 0.5 - triangleHeight * -Sin(angle) '下向きがyの正の向きであることに注意
    Dim vertexY = startY + dy * 0.5 - triangleHeight * Cos(angle)
    Dim mid1x = startX + trisectionLengthX
    Dim mid1y = startY + trisectionLengthY
    Dim mid2x = mid1x + trisectionLengthX
    Dim mid2y = mid1y + trisectionLengthY
    If level = 0 Then
        PSet (startX, startY), 7
        Line -(mid1x, mid1y), 7
        Line -(vertexX, vertexY), 7
        Line -(mid2x, mid2y), 7
        Line -(endX, endY), 7
    Else
        level--
        DrawKochCurveAB(startX, startY, mid1x, mid1y, level)
        DrawKochCurveAB(mid1x, mid1y, vertexX, vertexY, level)
        DrawKochCurveAB(vertexX, vertexY, mid2x, mid2y, level)
        DrawKochCurveAB(mid2x, mid2y, endX, endY, level)
    End If
End Sub

DrawKochCurveAB(10, 100, 300, 100, 3)
Sleep(-1)

スポンサード リンク

この記事のカテゴリ

  • ⇒ まだまだコッホ曲線: ABプロンプト画面