dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB
Expertise: Intermediate
Jan 2, 2007

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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

Private Sub Form_Load()
    'set the form up.    
    Me.ScaleMode = vbPixels
    Me.AutoRedraw = True
    Me.WindowState = vbMaximized
    
End Sub
Richard Bunt
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date