''' Sierpinski Fractal Pylie.com ''' import turtle order = 2 laki = turtle.Turtle() laki.shape('turtle') laki.color('darkblue', 'deepskyblue') laki.speed(5) points = [[-120,-30],[0,170],[120,-30]] def getMid(p1,p2): return ( (p1[0]+p2[0]) / 2, (p1[1] + p2[1]) / 2) def Sierpinski(points,order): laki.up() laki.goto(points[0][0],points[0][1]) laki.down() laki.left(60) laki.goto(points[1][0],points[1][1]) laki.right(120) laki.goto(points[2][0],points[2][1]) laki.right(120) laki.goto(points[0][0],points[0][1]) if order>0: Sierpinski([points[0], getMid(points[0], points[1]), getMid(points[0], points[2])], order-1) laki.right(120) Sierpinski([points[1], getMid(points[0], points[1]), getMid(points[1], points[2])], order-1) laki.right(120) Sierpinski([points[2], getMid(points[2], points[1]), getMid(points[0], points[2])], order-1) laki.right(120) Sierpinski(points,order)
اجرا کن
پاک کن