' Redraw the curve.
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles _
MyBase.Paint
DrawCurve(e.Graphics, _
Me.Width \ 2, Me.Height \ 2, _
0, 14 * PI, 0.1)
End Sub
' Draw the curve on the indicated Graphics object.
Private Sub DrawCurve(ByVal gr As Graphics, ByVal cx As _
Integer, ByVal cy As Integer, ByVal start_t As Single, _
ByVal stop_t As Single, ByVal dt As Single)
Dim num_pts As Integer
Dim pts() As PointF
Dim pt As Integer
Dim t As Single
Dim px As Single
Dim py As Single
' Allocate room for the points.
' Note that this allocates an array
' with indices from 0 to num_pts.
num_pts = (stop_t - start_t) / dt
ReDim pts(num_pts)
' Find the center of the drawing area.
px = cx + X(start_t)
py = cy + Y(start_t)
' Find the points.
t = start_t
For pt = 0 To num_pts - 1
pts(pt).X = cx + X(t)
pts(pt).Y = cy + Y(t)
t += dt
Next pt
' Close to the first point.
pts(num_pts) = pts(0)
' Draw the lines.
gr.DrawLines(New Pen(Color.Black), pts)
End Sub
|