# Fractals

The image is drawn via python script that carries out the below procedure.

## Order from chaos

Imagine you are inside an equalateral triangle. I'm not sure why, perhaps you're just fed up of squares. Now you pick a corner at random and walk towards it. When you are half way you stop, change your mind and put a dot on the floor. Then you repeat the same process, pick another corner and walk halfway to it. Just do this an infinite number of times. Guess what you pattern you'll make when you look at all the dots you've dropped. Surprisingly you would make Sierpinski's triangle (that thing above).

``````
import random
import math
from turtle import *

def sierpinski(depth, s=0):
#sets speed 0=fastest
speed(s)
#draws triangle to make fractal inside of
penup()
goto(0,(300*(3**0.5)))
#set the position of the top of the triangle
top = pos()
pendown()
goto(600,-(300*(3**0.5)))
#set the position of the bottom left of the triangle
left = pos()
goto(-600,-(300*(3**0.5)))
#set the position of the bottom right of the triangle
right = pos()
goto(0,(300*(3**0.5)))
#go back to the centre of the triangle
penup()
goto(0,0)
count = 0
#Array of vertices
vertex = [top, left, right]
#loop until depth of iteration is complete
while count < depth:
#store current location
location = pos()
#goto half-way between the current location and a random vertex
goto(0.5*(location + vertex[random.randint(0,2)]))
#make a dot. In this case size 6
dot(6)
#count them, well hey we are all mathematians here
count += 1
```
```