Due: 9:00 a.m., Wednesday, 3 March 2010
Summary: In this assignment, you will use turtles to explore mechanisms for constructing images based on a variety of polygons. Our focus will be on using lists, iteration, and anonymous procedures as ways to work with the turtle model.
Purposes: To give you more experience with the turtle model. To give you more comfort with anonymous procedures. To explore the complexities possible from simple operations.
Expected Time: Two to three hours.
Collaboration: We encourage you to work in groups of size three. You may, however, work alone or work in a group of size two or size four. You may discuss this assignment with anyone, provided you credit such discussions when you submit the assignment.
Submitting:
Email your answer to <weinman>. The title of your email
should have the form CSC151-01, 20010S Assignment 5: Polygons and
should contain your answers to all parts of the assignment. Scheme code
should be in the body of the message.
Warning: So that this assignment is a learning experience for everyone, we may spend class time publicly critiquing your work.
Write a procedure, (, that uses a turtle to draw a
regular polygon with the specified number of sides, with each side of
the specified length.
turtle-polygon!
turtle side-length
sides )
For example,
(turtle-polygon! t 100 3)
(turtle-polygon! t 100 4)
(turtle-polygon! t 60 5)
(turtle-polygon! t 40 6)
Your procedure must return the turtle to its original position and angle. Your procedure must not change the turtle's brush or color.
Hint: The sum of the interior angles of a polygon with
N sides is (N-2)*180.
Write a procedure, (, that draws the given number
of copies of the specified polygon, with the turtle turned an angle
of turtle-spin-polygon!
turtle side-length
sides angle
copies)angle between polygons.
For example,
(turtle-spin-polygon! t 50 4 15 10)
(turtle-spin-polygon! t 50 4 20 5)
(turtle-spin-polygon! t 50 4 5 20)
(turtle-spin-polygon! t 50 4 -30 5)
As is the case in problem one, your procedure must return the turtle to its original position and orientation.
Write a procedure, (, that draws the given number
of copies of the specified polygon, with each copy drawn with a
side length turtle-scale-polygon!
turtle initial-side-length
sides scale-factor
copies)scale-factor times the
the previous side length.
For example, if the initial side length is ten, and the scale factor is two, this procedure would draw polygons with side lengths 10, 20, 40, 80, 160, ....
Similarly, if the initial side length is 100, and the scale factor is 0.9, the procedure would draw polygons with side lengths 100, 90, 81, 72.9, ....
Here are some visual issues.
(turtle-scale-polygon! t 1 5 2 8)
(turtle-scale-polygon! t 1 5 1.2 30)
(turtle-scale-polygon! t 100 5 0.9 20)
As is the case in the previous problems, your procedure must return the turtle to its original position and orientation.
A potential deficiency of each of the prior two procedures is that multiple polygons are joined at a vertex. The problem is, of course, that our basic polygon procedure draws polygons starting at a particular point, rather than centered at a certain point.
Write a procedure, (, that uses turtle-centered-polygon!
turtle radius
sides)turtle
to draw a polygon of the appropriate number of sides, centered at the
current position of the turtle, and enclosed in a circle of radius
radiius.
Your procedure will likely:
radius;turtle-polygon!;radius to return
to the center; and
Note: For a polygon with interior angle a
and radius r, the side length is
2*r*sin(a/2).
As is the case in the previous problems, your procedure must return the turtle to its original position and orientation.
Write procedures, ( and
turtle-spin-centered-polygon!
turtle radius
sides angle
copies)(, that behave similarly to
turtle-scale-centered-polygon!
turtle initial-radius
sides scale-factor
copies)turtle-spin-polygon! and
turtle-scale-polygon!, except using
centered polygons.
Write a procedure, (, that makes the given number
of copies of the polygon, scaling and spinning each subsequent polygon.
turtle-spin-and-scale-centered-polygon!
turtle initial-radius
sides angle
scale-factor
copies)
Write a program that systematically generates an interesting image composed of a series of polygons. In addition to spinning and scaling polygons, you may find it useful to shift their position, change their color or brush, or even change the number of sides between subsequent polygons.
We will judge your solutions on their correctness, their conciseness, and the cleverness.