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
 
 
 
 
 
TitleDraw strange attractors (fractals)
DescriptionThis example shows how to draw strange attractors (fractals) in Visual Basic 6.
Keywordsstrange attractor, fractal, equation, graphics
CategoriesGraphics, Algorithms
 
If you plot a sequence of point (x1, y1), (x1, y2), ..., the points can settle into one of several patterns. For example, they can enter a repeating cycle, tend towards infinity, or look chaotic. Another option is following a strange attractor. In that case, the points clearly follow some pattern but not an obvious repeating cycle.

This example plots points given by the equations:

    X' = A0 + A1 * x + A2 * x * x + A3 * x * y + A4 * y + A5 * y * y
    Y' = A6 + A7 * x + A8 * x * x + A9 * x * y + A10 * y + A11 * y * y

For various values of A1, A2, ... A11.

The program uses a Timer to plot points. The following code shows the Tick event handler that draws the curve. It plots 1,000 points at a time to improve performance and reduce flicker. For each iteration, the routine generates the next (X, Y) point and draws it on the Bitmap named m_Bitmap. After it has finished its 1,000 points, it draws the Bitmap onto the picCanvas control so you can see the result.

 
Private X As Double
Private Y As Double

Private Sub tmrDrawPoint_Timer()
Dim i As Integer
Dim new_x As Double
Dim new_y As Double
Dim pix_x As Integer
Dim pix_y As Integer

    For i = 1 To 100
        new_x = A(0) + A(1) * X + A(2) * X * X + A(3) * X * _
             Y + A(4) * Y + A(5)
* Y * Y
        new_y = A(6) + A(7) * X + A(8) * X * X + A(9) * X * _
             Y + A(10) * Y +
A(11) * Y * Y
        X = new_x
        Y = new_y

        pix_x = (X - m_Wxmin) / m_Wwid * m_Wid
        pix_y = m_Hgt - (Y - m_Wymin) / m_Whgt * m_Hgt - 1
        If (pix_x >= 0) And (pix_x < m_Wid) And _
           (pix_y >= 0) And (pix_y < m_Hgt) _
        Then
            picCanvas.PSet (pix_x, pix_y), vbBlue
        End If
    Next i
End Sub
 
See the code for further details.

For more information on this kind of strange attractor, see Strange Attractor by Eric W. Weisstein from MathWorld--A Wolfram Web Resource.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated