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 a fractal Hilbert curve
DescriptionThis example shows how to draw a fractal Hilbert curve in Visual Basic.
Keywordsfractal, Hilbert curve
CategoriesGraphics
 
The remarkably short Hilbert subroutine draws the Hilbert curve. It takes as parameters the depth of recursion, and dx and dy values that give the direction in which it should draw. It recursively draws four smaller Hilbert curves and connects them with lines.

 
' Draw a Hilbert curve.
Private Sub Hilbert(ByVal depth As Integer, ByVal dx As _
    Single, ByVal dy As Single)
    If depth > 1 Then Hilbert depth - 1, dy, dx
    picCanvas.Line -Step(dx, dy)
    If depth > 1 Then Hilbert depth - 1, dx, dy
    picCanvas.Line -Step(dy, dx)
    If depth > 1 Then Hilbert depth - 1, dx, dy
    picCanvas.Line -Step(-dx, -dy)
    If depth > 1 Then Hilbert depth - 1, -dy, -dx

    If m_Refresh Then picCanvas.Refresh
End Sub
 
Check the program's Refresh box to make it update its display as it draws each line. This slows the program down greatly but lets you see the order in which the routine draws its lines.

For more information on fractals, see my book Visual Basic Graphics Programming.

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