  Advertiser Disclosure
 TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK Specialized Dev Zones Research Center eBook Library .NET Java C++ Web Dev Architecture Database Security Open Source Enterprise Mobile Special Reports 10-Minute Solutions DevXtra Blogs Slideshow     Language: VB
Expertise: Intermediate
Jan 2, 2007

### WEBINAR:On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning

# How to Draw a Spiral in VB

Using a loop and the mathematical formula for a spiral, you can use pset(x,y) to plot the points returned by the formulas. The variables a and b determine the shape of the spiral. Generally, smaller numbers mean a tighter spiral. The following code shows an exponential spiral wherein the distance from the origin increases drastically with each rotation:
``````
Option Explicit
Private Const Pi As Double = 3.14159265358979
Private Const e As Double = 2.718281828

Private Sub cmdDraw_Click()
Dim cX As Long, X As Long
Dim cy As Long, Y As Long
'get the center of the form.
cX = Me.ScaleWidth / 2
cy = Me.ScaleHeight / 2
a = 0.15
b = 0.15

'loop round to plot the points of the spiral.
For i = 0 To 23040
ang = (Pi / 720) * i
X = cX + (a * (Cos(ang)) * (e ^ (b * ang)))
Y = cy - (a * (Sin(ang)) * (e ^ (b * ang)))
Me.PSet (X, Y)
Next i

End Sub

'set the form up.
Me.ScaleMode = vbPixels
Me.AutoRedraw = True
Me.WindowState = vbMaximized

End Sub
``````
Richard Bunt Submit a Tip Browse "Application Design" Tips Browse All Tips   Thanks for your registration, follow us on our social networks to keep up-to-date