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 curlicue fractal in Visual Basic .NET
DescriptionThis example shows how to make a curlicue fractal in Visual Basic .NET.
Keywordscurlicue, fractal, VB.NET
CategoriesGraphics, VB.NET
 
See Curlicue Fractal by Eric W. Weisstein from MathWorld, a Wolfram Web Resource.

The program starts by drawing a line segment in the direction of the X axis. It then iteratively calculates theta and phi using these equations:

    theta(n + 1) = (theta(n) + 2 * Pi * S) Mod (2 * Pi)
    phi(n + 1) = (theta(n) + phi(n)) Mod (2 * Pi)

for some irrational number S. At each step, the program draws a new line segment in the direction given by phi.

Subroutine DrawCurlicue draws 10,000 segments following these rules.

 
Private Sub DrawCurlicue(ByVal gr As Graphics)
    Const SCALE As Integer = 2
    gr.ScaleTransform( _
        SCALE, _
        SCALE, _
        MatrixOrder.Append)
    gr.TranslateTransform( _
        picCanvas.ClientSize.Width \ 2, _
        picCanvas.ClientSize.Width \ 2, _
        MatrixOrder.Append)

    Dim s As Single = Single.Parse(txtS.Text)

    Dim theta As Single = 0
    Dim phi As Single = 0
    Dim x0, y0, x1, y1 As Single
    x0 = 0
    y0 = 0
    Dim thin_pen As New Pen(Color.Black, 0)
    For i As Integer = 1 To 10000
        x1 = x0 + Cos(phi)
        y1 = y0 + Sin(phi)
        gr.DrawLine(thin_pen, x0, -y0, x1, -y1)
        x0 = x1
        y0 = y1

        phi = (theta + phi) Mod (2 * PI)
        theta = (theta + 2 * PI * s) Mod (2 * PI)
    Next i
    thin_pen.Dispose()
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated