|
2009/09/27(Sun) 23:00:07 編集(投稿者) 2009/09/27(Sun) 23:00:03 編集(投稿者)
<pre><pre>■No41672 (たくボン さん) に返信 > ■No41669 (aki さん) に返信
とりあえず何も重みを考慮してない曲線描画のサンプル。
'CurveLine.vb Public Class CurveLine Public Corners As New List(Of Point) Public Sub New(ByVal pos As Point) Me.AddCorner(pos) End Sub Public Sub AddCorner(ByVal pos As Point) Me.Corners.Add(pos) End Sub Public Sub Draw(ByVal g As Graphics, ByVal p As Pen) g.DrawCurve(p, Me.Corners.ToArray) End Sub End Class
'Form1.vb Public Class Form1 Dim ActiveCurve As CurveLine = Nothing Dim Curves As New List(Of CurveLine) Dim pen1 As Pen Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.pen1 = New Pen(Color.Green, 80) End Sub Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown Me.ActiveCurve = New CurveLine(e.Location) End Sub Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove If Me.ActiveCurve IsNot Nothing Then Me.ActiveCurve.AddCorner(e.Location) Me.PictureBox1.Refresh() End Sub Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp If Me.ActiveCurve IsNot Nothing Then Me.ActiveCurve.AddCorner(e.Location) Me.Curves.Add(Me.ActiveCurve) Me.ActiveCurve = Nothing End If Me.PictureBox1.Refresh() End Sub Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint For Each cl As CurveLine In Me.Curves cl.Draw(e.Graphics, Me.pen1) Next If Me.ActiveCurve IsNot Nothing Then Me.ActiveCurve.Draw(e.Graphics, Me.pen1) End Sub End Class
開始と終了の線端の形状は、イラレとかのドローソフトを参考にして、角丸や円形に変更すればいいと思うです:-) あとは、重みとかを考慮するとかしないと、連続で曲線を引くと当然重くなるから注意が必要かな。 可能ならベジエにするのもいいと思うけど、そこらは時間がないから勉強してみてください。 </pre></pre>
|