Fractals
#2
Sierpinski Flies a Kite

Here is probably my 2nd favorite fractal, a happy accident while playing around with Ashish Kite fractal.

Code: (Select All)
_Title "Sierpinski flies a kite by bplus 2017-10-16"
' after playing with Ashish Kite Fractal

Screen _NewImage(1200, 700, 32)
_ScreenMove 100, 20
While 1
    Cls
    drawKite 600, 540, 200, a
    _Display
    _Limit 20
    a = a + _Pi(2 / 360)
Wend
Sleep
Sub drawKite (xx, yy, s, a)
    x = xx: y = yy
    x2 = x + 3 * s * Cos(_Pi(1 / 2) - a / 2): y2 = y + 3 * s * Sin(_Pi(1 / 2) - a / 2)
    x3 = x + 3 * s * Cos(_Pi(1 / 2) + a / 2): y3 = y + 3 * s * Sin(_Pi(1 / 2) + a / 2)
    SierLineTri x, y, x2, y2, x3, y3, 0
    'LINE (x, y)-(x + s * COS(_PI(2) - a / 2), (y - s) + s * SIN(_PI(2) - a / 2))
    'LINE (x, y)-(x + s * COS(_PI + a / 2), (y - s) + s * SIN(_PI + a / 2))

    If s > 10 Then
        drawKite x + 1 * s * Cos(_Pi(2) - a), (y - s) + 1 * s * Sin(_Pi(2) - a), s / 2, a
        drawKite x + 1 * s * Cos(_Pi + a), (y - s) + 1 * s * Sin(_Pi + a), s / 2, a
    End If
End Sub
Sub SierLineTri (x1, y1, x2, y2, x3, y3, depth)
    If depth = 0 Then 'draw out triangle if level 0
        Line (x1, y1)-(x2, y2)
        Line (x2, y2)-(x3, y3)
        Line (x1, y1)-(x3, y3)
    End If
    'find midpoints
    If x2 < x1 Then mx1 = (x1 - x2) / 2 + x2 Else mx1 = (x2 - x1) / 2 + x1
    If y2 < y1 Then my1 = (y1 - y2) / 2 + y2 Else my1 = (y2 - y1) / 2 + y1
    If x3 < x2 Then mx2 = (x2 - x3) / 2 + x3 Else mx2 = (x3 - x2) / 2 + x2
    If y3 < y2 Then my2 = (y2 - y3) / 2 + y3 Else my2 = (y3 - y2) / 2 + y2
    If x3 < x1 Then mx3 = (x1 - x3) / 2 + x3 Else mx3 = (x3 - x1) / 2 + x1
    If y3 < y1 Then my3 = (y1 - y3) / 2 + y3 Else my3 = (y3 - y1) / 2 + y1

    Line (mx1, my1)-(mx2, my2) '  'draw all inner triangles
    Line (mx2, my2)-(mx3, my3)
    Line (mx1, my1)-(mx3, my3)

    If depth < 4 Then 'not done so call me again
        SierLineTri x1, y1, mx1, my1, mx3, my3, depth + 1
        SierLineTri x2, y2, mx1, my1, mx2, my2, depth + 1
        SierLineTri x3, y3, mx3, my3, mx2, my2, depth + 1
    End If
End Sub

Love the way the triangles dance on the screen!
   
b = b + ...
Reply


Messages In This Thread
Fractals - by bplus - 05-19-2022, 07:34 PM
RE: Fractals - by bplus - 05-19-2022, 07:46 PM
RE: Fractals - by bplus - 05-19-2022, 07:52 PM
RE: Fractals - by bplus - 05-19-2022, 08:03 PM
RE: Fractals - by bplus - 05-19-2022, 08:25 PM
RE: Fractals - by bplus - 05-19-2022, 08:33 PM
RE: Fractals - by TarotRedhand - 05-19-2022, 10:33 PM
RE: Fractals - by bplus - 05-20-2022, 01:14 AM
RE: Fractals - by TarotRedhand - 05-20-2022, 07:01 AM
RE: Fractals - by bplus - 05-20-2022, 03:55 PM
RE: Fractals - by TarotRedhand - 05-21-2022, 10:12 PM
RE: Fractals - by bplus - 05-21-2022, 11:16 PM
RE: Fractals - by bplus - 05-21-2022, 11:33 PM
RE: Fractals - by bplus - 06-03-2022, 03:37 PM
RE: Fractals - by bplus - 06-03-2022, 03:43 PM



Users browsing this thread: 2 Guest(s)