""" CSCI146 Programming Assignment 6 Name: Section: Creativity: """ import turtle as t def gcd(a, b): pass # Sample calls for testing # gcd(36, 81) # gcd(13, 6) def stairs(length, levels): pass # Sample calls for testing # stairs_demo(300, 1) # stairs_demo() def sierpinski(length, level): pass # Sample calls for testing # sierpinski_demo(300, 1) # sierpinski_demo() def recursive_h(length, level): pass # Sample calls for testing # recursive_h_demo(200, 1) # recursive_h_demo() # When all is complete, create screenshot using # drawing_demo() # Testing code is provided below that calls the recursive functions above def stairs_demo(length=256, levels=5): """ Set up for stairs drawing and call stairs(). First moves the turtle to the top left of the screen, then calls stairs() to draw a staircase of squares. Calls turtle.done() at the end of drawing. Args: length: side length of top square in pixels levels: number of boxes to draw """ # Pick up the pen and move the turtle so it starts at the left edge of the canvas, pointing right t.penup() t.goto(-t.window_width()/2 + 20, t.window_height()/2 - 20) t.setheading(0) t.pendown() # Draw the stairs by calling recursive function stairs(length, levels) # Finish t.done() def sierpinski_demo(length=300, level=4): """ Set up for sierpinski drawing and call sierpinski(). First moves the turtle to the left edge of the drawing window, turns off tracer, and then calls sierpinski(). Calls turtle.done() at end of drawing. Args: length: base length of Sierpinski triangle in pixels level: complexity level of Sierpinski triangle """ if level > 2: # Turn off animation (too slow for many iterations) t.tracer(False) # Pick up the pen and move the turtle so it starts at the left edge of the canvas, pointing right t.penup() t.goto(-t.window_width()/3 + 20, 0) t.setheading(0) t.pendown() sierpinski(length, level) # Finish t.update() # Need update() if using tracer(False) t.done() def recursive_h_demo(length=150, level=3): """ Set up for recursive_h drawing and call recursive_h(). Turns tracer off, calls recursive_h(), and ends with turtle.done(). Args: length: height of innermost H in pixels level: complexity level of recursive H """ if level > 2: # Turn off animation (too slow for many iterations) t.tracer(False) recursive_h(length, level) t.update() # need update() if using tracer(False) t.done() def drawing_demo(): """ Create drawings of `stairs`, `sierpinski`, and `recursive_h`. Args: None """ t.tracer(False) # draw stairs in upper left of drawing window t.penup() t.goto(-t.window_width()/2 + 20, t.window_height()/2 - 20) t.setheading(0) t.pendown() stairs(150, 6) # draw sierpinski in upper right of drawing window t.penup() t.goto(0, t.window_height()/2 - 300) t.setheading(0) t.pendown() sierpinski(300, 5) # draw recursive H in lower half of drawing window t.penup() t.goto(0, -t.window_height()/4) t.setheading(0) t.pendown() recursive_h(150, 4) # finish t.update() t.done()