Create a file named polygons.py
.
As a first step towards drawing polygons in general, write a
function calc_angle
that takes a number of sides as an argument, and returns the number of
degrees in
the angle that the turtle should turn when drawing such a polygon. (For
example,
for a triangle, it should return 120, as we saw in class.)
Write a function draw_polygon(tortoise, n_sides, side_length)
that has the
given turtle draw a regular polygon with the given number of sides and
the
given length. Your function must return the turtle to its original
position and
angle, and it must not change the turtle’s color.
Use the calc_angle
function that you wrote for part 1
to determine how
far to turn the turtle as you draw these polygons.
Write a function spin_polygon(tortoise, n_sides, side_length,
angle, n_copies)
that draws the specified number of copies of a polygon (using your draw_polygon
function,) with the turtle turned by angle between each of
the polygons.
Here are some examples of this function being called on a turtle
named kat
:
spin_polygon(kat, 4, 50, 30, 5)
spin_polygon(kat, 4, 50, -30, 3)
spin_polygon(kat, 4, 5, 10, 360 // 10)
As in the previous problems, your function must return the turtle to its original position and heading.
Write a function scale_polygon(tortoise, n_side, side_length,
scale_factor, n_copies)
that draws a given number of copies of the specified polygon, with each
copy drawn
with a side length scale_factor
times the previous side
length.
For example, if the initial side_length
is ten and the
scale_factor
is two, the
side lengths of drawn polygons should be 10, 20, 40, 80, …
Here are some examples of this function being called on a turtle
named tess
:
scale_polygon(tess, 5, 10, 2, 4)
scale_polygons(tess, 5, 1, 1.2, 25)
As in the previous problems, your function must return the turtle to its original position and heading.
Submit one file, polygons.py
,
using the turnin form.
calc_angle
- 2 pts draw_polygon
- 4 pts spin_polygon
- 4 pts scale_polygon
- 4 pts Created September 15, 2016
Last revisedSeptember 15, 2016, 12:25:22 PM PDT
This work is licensed under a Creative
Commons Attribution-Noncommercial-Share Alike 3.0 United States License.