BLOG.CSHARPHELPER.COM: Draw a Hilbert curve fractal in C#
Draw a Hilbert curve fractal in C#
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.
Because C# doesn't provide a simple relative line drawing method, the code includes one. The DrawRelative function draws a line from the point (m_X, m_Y) to a new point and stores the point's coordinates in the variables m_X and m_Y.
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 depth greater than around 4 or 5.
Comments