Blog

Fractal Snowflake Challenge:

Fractal Snowflake Challenge:

The following snowflake is built using two recognizable fractal patterns: the Koch Snowflake and the Sierpinski Triangle. The final design is generated by a computer program and is comprised completely of small blue triangles. How many small blue triangles are in the image? You can download high-resolution versions of the snowflake in a variety of formats: .dwg, .wmf, and .pdf. Also, the source code of the program that generated the snowflake is given below.

Which is the total number of blue triangles?
A:    6144
B:    9216
C:    10830
D:    19683

The winner will go to the correct answer with the best engineering content. Submit your responses to geekchallenge@dmcinfo.com.

A snowfalke made of fractal patters Koch Snowflake and Sierpinski Triangle.

Download the .wmf file.

Download the .pdf file.

The winner will go to the correct answer with the best engineering content. Submit your responses to geekchallenge@dmcinfo.com.

Extra Credit:  

Create a higher order version of this Fractal Snowflake, and send in your image and code.  I made mine in Microsoft Visio using this macro code:

Public Const Pi As Double = 3.14159265358979
Sub FullSnowflakePattern()
    Call CombinedFractal(6, 6)
End Sub
Sub CombinedFractal(ByVal KochLevel As Integer, SierpinskiLevel As Integer)
    Dim vertexX As Double
    Dim vertexY As Double
    Dim x1 As Double
    Dim y1 As Double
    Dim x2 As Double
    Dim y2 As Double
    x1 = 0.25
    y1 = 3
    x2 = 8.25
    y2 = 3
    Call Sierpinski(SierpinskiLevel, x1, y1, x2, y2, Sqr(3), vertexX, vertexY)
    'bottom side
    Call KochSide(KochLevel, SierpinskiLevel, x2, y2, x1, y1, Root3)
    ' Left side
    Call KochSide(KochLevel, SierpinskiLevel, x1, y1, vertexX, vertexY, Root3)
    'Right side
    Call KochSide(KochLevel, SierpinskiLevel, vertexX, vertexY, x2, y2, Root3)
End Sub

Sub KochSide(ByVal KochLevel As Integer, ByVal SierpinskiLevel As Integer, ByVal x1 As Double, ByVal y1 As Double, ByVal x2 As Double, ByVal y2 As Double, ByVal Root3 As Double)
    Dim vertexX As Double
    Dim vertexY As Double
    Dim BaseX1 As Double
    Dim BaseY1 As Double
    Dim BaseX2 As Double
    Dim BaseY2 As Double
    
    If KochLevel > 0 Then
        BaseX1 = (2 * x1 + x2) / 3
        BaseY1 = (2 * y1 + y2) / 3
        BaseX2 = (2 * x2 + x1) / 3
        BaseY2 = (2 * y2 + y1) / 3
        Call Sierpinski(SierpinskiLevel - 1, BaseX1, BaseY1, BaseX2, BaseY2, Sqr(3), vertexX, vertexY)
        Call KochSide(KochLevel - 1, SierpinskiLevel - 1, BaseX1, BaseY1, vertexX, vertexY, Root3)
        Call KochSide(KochLevel - 1, SierpinskiLevel - 1, vertexX, vertexY, BaseX2, BaseY2, Root3)
        Call KochSide(KochLevel - 1, SierpinskiLevel - 1, x1, y1, BaseX1, BaseY1, Root3)
        Call KochSide(KochLevel - 1, SierpinskiLevel - 1, BaseX2, BaseY2, x2, y2, Root3)
    End If
End Sub

Sub Sierpinski(ByVal Levels As Integer, ByVal x1 As Double, ByVal y1 As Double, ByVal x2 As Double, ByVal y2 As Double, ByVal Root3 As Double, outVertexX As Double, outVertexY As Double)
    Dim MidX As Double
    Dim MidY As Double
   Dim Vector12x As Double
    Dim Vector12y As Double
    Dim vertexX As Double
    Dim vertexY As Double
    Dim Junk1 As Double
    Dim Junk2 As Double
    
    MidX = (x1 + x2) / 2
    MidY = (y1 + y2) / 2
    Vector12x = x2 - x1
    Vector12y = y2 - y1
    vertexX = MidX - Vector12y * Root3 / 2
    vertexY = MidY + Vector12x * Root3 / 2
    
    If Levels > 0 Then
        Call Sierpinski(Levels - 1, x1, y1, MidX, MidY, Root3, Junk1, Junk2)
        Call Sierpinski(Levels - 1, MidX, MidY, x2, y2, Root3, Junk1, Junk2)
        Call Sierpinski(Levels - 1, (x1 + vertexX) / 2, (y1 + vertexY) / 2, (x2 + vertexX) / 2, (y2 + vertexY) / 2, Root3, Junk1, Junk2)
    Else
        Dim CentroidX As Double
        Dim CentroidY As Double
        CentroidX = (x1 + x2 + vertexX) / 3
        CentroidY = (y1 + y2 + vertexY) / 3
        Call MakeTriangle(Vector12x, Vector12y, CentroidX, CentroidY, Root3)
    End If
    outVertexX = vertexX
    outVertexY = vertexY
End Sub

Sub MakeTriangle(ByVal VectorX As Double, ByVal VectorY As Double, ByVal CentroidX As Double, ByVal CentroidY As Double, ByVal Root3 As Double)
    Dim Angle As Double
    Dim Width As Double
    Dim Height As Double
    Dim shpNew As Visio.Shape
    
    Set shpNew = ActivePage.Drop(Application.Documents.Item("BASIC_U.VSSX").Masters.ItemU("Triangle"), CentroidX, CentroidY)
    Width = Sqr(VectorX * VectorX + VectorY * VectorY)
    Height = Width * Root3 / 2
    Angle = Atan2(VectorY, VectorX)
    
    shpNew.CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).FormulaU = Width
    shpNew.CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).FormulaU = Height
    shpNew.CellsSRC(visSectionObject, visRowXFormOut, visXFormAngle).FormulaU = Angle
    shpNew.CellsSRC(visSectionObject, visRowFill, visFillForegnd).FormulaU = "THEMEGUARD(MSOTINT(THEMEVAL(""AccentColor4""),40))"
    shpNew.CellsSRC(visSectionObject, visRowFill, visFillPattern).FormulaU = "1"
    shpNew.CellsSRC(visSectionObject, visRowGradientProperties, visFillGradientEnabled).FormulaU = "FALSE"
    shpNew.CellsSRC(visSectionObject, visRowLine, visLinePattern).FormulaU = "0"
    shpNew.CellsSRC(visSectionObject, visRowGradientProperties, visLineGradientEnabled).FormulaU = "FALSE"
End Sub

Public Function Atan2(ByVal y As Double, ByVal x As Double) As Double

   If y > 0 Then
     If x >= y Then
       Atan2 = Atn(y / x)
     ElseIf x <= -y Then
       Atan2 = Atn(y / x) + Pi
     Else
       Atan2 = Pi / 2 - Atn(x / y)
     End If
   Else
     If x >= -y Then
       Atan2 = Atn(y / x)
     ElseIf x <= y Then
       Atan2 = Atn(y / x) - Pi
     Else
       Atan2 = -Atn(x / y) - Pi / 2
     End If
   End If

End Function

Comments

There are currently no comments, be the first to post one.

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above:

Related Blog Posts