# file: stripes.py # # date: Oct. 25, 2007 # # author: Bob Muller, CS074 Digital World; Fall 2007 # # This file contains a few simple python functions that use the turtle # graphics system to draw colored stripes across the turtle window. # import turtle def setup(w, h): turtle.setup(width=w, height=h) turtle.degrees() turtle.up() # stripe accepts the y coordinate of a stripe, the height of a stripe and # its color. # def stripe(y, stripeHeight, color): turtle.color(color) windowWidth = turtle.window_width() right = windowWidth / 2 left = - right turtle.goto(left, y) turtle.begin_fill() turtle.goto(right, y) turtle.goto(right, y + stripeHeight) turtle.goto(left, y + stripeHeight) turtle.goto(left, y) turtle.end_fill() # stripes accepts the number of stripes required and two alternating # colors. Once stripes.setup has been called, stripes can be called as in: # # stripes.stripes(10,'Blue','Green') # def stripes(n, color1, color2): windowHeight = turtle.window_height() top = windowHeight / 2 bottom = - top stripeHeight = windowHeight / n y = top - stripeHeight colorFlag = True while y >= bottom: if colorFlag: stripe(y, stripeHeight, color1) else: stripe(y, stripeHeight, color2) y = y - stripeHeight colorFlag = not(colorFlag)