Python recursion , Sierpinski triangle with color at each depth

Posted by ???? ??? on Stack Overflow See other posts from Stack Overflow or by ???? ???
Published on 2012-12-02T05:01:13Z Indexed on 2012/12/02 5:03 UTC
Read the original article Hit count: 683

Filed under:
|
|
|

import turtle w=turtle.Screen()

def Tri(t, order, size):

if order==0:

    t.forward(size)

    t.left(120)

    t.forward(size)

    t.left(120)

    t.forward(size)

    t.left(120)

else:

    t.pencolor('red')

    Tri(t, order-1, size/2, color-1)

    t.fd(size/2)

    t.pencolor('blue')

    Tri(t, order-1, size/2, color-1)

    t.fd(size/2)

    t.lt(120)

    t.fd(size)

    t.lt(120)

    t.fd(size/2)

    t.lt(120)

    t.pencolor('green')

    Tri(t, order-1, size/2,color-1)

    t.rt(120)

    t.fd(size/2)

    t.lt(120)

can anyone help with this problem ? i want to a sierpinski triangle that have color at specific depth like this http://openbookproject.net/thinkcs/python/english3e/_images/sierpinski_color.png

i dont know how to make the the triangle color change at specific depth

© Stack Overflow or respective owner

Related posts about python

Related posts about recursion