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. I changed the pencolor after each side of a hexagon was drawn. I used Python's 'randint()' method to generate random integers for the red, green and blue components of each color. To use random integers, use 'from random import randint' at the top of your program. In your program, you want the statement 'turtle.colormode(255)' to indicate that the numbers you'll supply will be between 0 and 255. You use 'randint' like this: 'red = randint(0, 255)'. (Use similar code for 'blue' and 'green'.) Then 'turtleName.pencolor(red, green, blue)' will cause the turtle to draw with that color.

The video below shows this function running.