Python turtle module confusion

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-05-08T16:02:20Z Indexed on 2010/05/08 16:08 UTC
Read the original article Hit count: 372

Filed under:
|
|

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)

© Stack Overflow or respective owner

Related posts about python

Related posts about turtle