Home Search   What's New Index Books Links Q & A Newsletter Banners   Feedback Tip Jar MSDN Visual Basic Community

Title Graph a parametric function (X(t), Y(t)) This example shows how to graph a parametric function (X(t), Y(t)) in Visual Basic 6. graph, parametric, curve, variable Graphics, Algorithms

This program draws axes. It then lets variable t run from 0 to 2*PI in small steps, connecting the points generated by the parametric functions.

```Private Sub Form_Load()
Const PI = 3.14159265
Dim x As Single
Dim y As Single
Dim r As Single
Dim t As Single
Dim dt As Single

' Set a convenient scale.
picGraph.AutoRedraw = True
picGraph.Scale (-2, 2)-(2, -2)

' Draw axes.
picGraph.Line (-2, 0)-(2, 0), vbBlue
For x = -2 To 2 Step 0.5
picGraph.Line (x, -0.1)-(x, 0.1), vbBlue
Next x
picGraph.Line (0, -2)-(0, 2), vbBlue
For y = -2 To 2 Step 0.5
picGraph.Line (-0.1, y)-(0.1, y), vbBlue
Next y

' Draw the parametric curve.
t = 0
dt = PI / 100
picGraph.CurrentX = 0
picGraph.CurrentY = 0
Do While t <= 2 * PI
r = 2 * Sin(5 * t)
x = r * Cos(t)
y = r * Sin(t)
picGraph.Line -(x, y)
t = t + dt
Loop
picGraph.Line -(0, 0)
End Sub```