Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a swirl
DescriptionThis example shows how to make a swirl in Visual Basic 6.
Keywordsswirl
CategoriesGraphics
 

See Swirl by Eric W. Weisstein from MathWorld, a Wolfram Web Resource.

The program plots points in polar coordinates where the intensity of a point is given by:

    F(r, t) = Sin(6 * Cos(r) - n * t)

Subroutine DrawSwirl draws the fractal. For each pixel in the output area, the routine calculates the corresponding polar coordinates (r, t) and then plugs r and t into the equation above.

 
Private Sub DrawSwirl()
Const MY_SCALE As Single = 10

Dim n As Single
Dim cx As Single
Dim cy As Single
Dim r As Single
Dim theta As Single
Dim x As Integer
Dim y As Integer
Dim dy As Single
Dim dy2 As Single
Dim dx As Single
Dim f As Single
Dim b As Integer

    On Error Resume Next
    n = CSng(txtN.Text)
    If Err.Number <> 0 Then Exit Sub
    On Error GoTo 0

    picCanvas.Cls

    cx = picCanvas.ScaleWidth / 2
    cy = picCanvas.ScaleHeight / 2
    For y = 0 To picCanvas.ScaleHeight - 1
        dy = (y - cy) / MY_SCALE
        dy2 = dy * dy
        For x = 0 To picCanvas.ScaleWidth - 1
            dx = (x - cx) / MY_SCALE
            r = Sqr(dx * dx + dy2)
            If dx = 0 And dy = 0 Then
                theta = 0
            Else
                theta = Atan2(dy, dx)
            End If
            f = Sin(6 * Cos(r) - n * theta)
            b = Int(128 + 127 * f)
            picCanvas.PSet (x, y), RGB(0, 0, b)
        Next x
    Next y
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated