Python

Turtle Geometry

8 points

Introduction

This program uses the 'turtle' module of Python to draw some geometric shapes.

First create a function that draws a geometric shape (I drew a hexagon).

The video below shows this function running.

 

Next, create a function that repeatedly calls the function you wrote above. After each function call, the turtle should make a small turn.

The video below shows this function running.

 

Starting Point

Download TurtleGeometry.py as a starting point for the project. The file guides you towards completing the program.

 

Extra Credit

2 points

Use the .pencolor() function in turtle graphics to use different colors in drawing your shape. (You could change the pencolor after each side of a figure is drawn.) You can use Python's 'randint()' method to generate random integers for the red, green and blue components of each color. To use 'randint()', put 'from random import randint' at the top of your program. You use 'randint' like this: 'red = randint(0, 255)', which will set 'red' to a number between 0 and 255 (including 0 and 255). (Use similar code for 'blue' and 'green'.) Then 'yourTurtleName.pencolor(red, green, blue)' will cause the turtle to draw with that color. In your program, include the statement 'turtle.colormode(255)' to indicate that the numbers you'll supply will be between 0 and 255.

The video below shows this function running.