views:

149

answers:

0

Hi, I'm trying to to add more lines to the triangle, so instead of 3 leading off there will be 5 depending on the parameter given but I really have no idea what to do at this stage and any help would be very welcome. Thanks in advance!:)

def draw_sierpinski_triangle(tracer_on, colour, initial_modulus, line_width, initial_heading,initial_x, initial_y, steps):

    turtle=Turtle()
    turtle.name = 'Mother of all turtles'
    turtle.reset ()
    turtle.tracer (tracer_on)
    turtle.speed ('fastest')
    turtle.color (colour)
    turtle.width (line_width)
    turtle.up()
    turtle.goto (initial_x, initial_y)
    turtle.down()
    turtle.set_heading (initial_heading)

    draw_sub_pattern (tracer_on, turtle, initial_modulus, 0, steps)

def draw_sub_pattern (tracer_on, turtle, modulus, depth, steps):

    if (depth >= steps):
        return;

    x, y = turtle.position ()
    heading = turtle.heading ()

    # draw the pattern
    turtle.up()
    turtle.down()
    turtle.forward (modulus)

    draw_sub_pattern(tracer_on, turtle, modulus * 0.5, depth + 1, steps)

    turtle.up()
    turtle.goto(x, y)
    turtle.down()
    turtle.set_heading (heading + 120)
    turtle.forward (modulus)

    draw_sub_pattern(tracer_on, turtle, modulus * 0.5, depth + 1, steps)

    turtle.up()
    turtle.goto(x, y)
    turtle.down()
    turtle.set_heading (heading + 240)
    turtle.forward (modulus)

    draw_sub_pattern(tracer_on, turtle, modulus * 0.5, depth + 1, steps)