ベジエ曲線の描画(VB)

説明:

連続する複数のベジエ曲線群を、アニメーションさせながらランダムに描画する。

キーワード:

PolyBezier

サンプルコード:

Private Sub Command1_Click()
    Const Speed As Single = 1
    Const PointNum As Long = 31 '3の倍数+1
    
    Dim Points(PointNum - 1) As POINT
    Dim X(PointNum - 1) As Single
    Dim Y(PointNum - 1) As Single
    Dim DX(PointNum - 1) As Single
    Dim DY(PointNum - 1) As Single
    Dim I As Long
    Dim J As Long
    
    For I = 0 To PointNum - 1
        X(I) = Rnd * 200
        Y(I) = Rnd * 200
        DX(I) = Rnd * Speed - Speed / 2
        DY(I) = Rnd * Speed - Speed / 2
    Next
    
    Picture1.AutoRedraw = True
    
    For J = 0 To 3000
        For I = 0 To PointNum - 1
            If X(I) + DX(I) < 0 Or X(I) + DX(I) > 200 Then DX(I) = -DX(I)
            If Y(I) + DY(I) < 0 Or Y(I) + DY(I) > 200 Then DY(I) = -DY(I)
            X(I) = X(I) + DX(I)
            Y(I) = Y(I) + DY(I)
            Points(I).X = X(I)
            Points(I).Y = Y(I)
        Next
    
'よりなめらかな曲線を書くには、以下のコメントを外す
'        For I = 3 To PointNum - 2 Step 3
'            Points(I).X = (X(I - 1) + X(I + 1)) / 2
'            Points(I).Y = (Y(I - 1) + Y(I + 1)) / 2
'        Next
        
        Picture1.Cls
        PolyBezier Picture1.hDC, Points(0), PointNum
    
        DoEvents
    Next
End Sub

(original text:1999/02/23 更新)

本ドキュメントの内容は保証しません。本ドキュメントによって生じた結果について、一切の責任を負いません。