Functional Problem Solving (CSC 151 2016S) : Assignments
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [Remote] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2016S)] [Davis (2013F)] [Rebelsky (2015F)] [Weinman (2014F)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Due: 10:30 p.m., 12 April 2016
Summary: In this assignment, you will use turtles to create images using iteration, recursion, and a mix of both techniques.
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.
Collaboration: You must work with assigned partners on this assignment. You may discuss this assignment with anyone, provided you credit such discussions when you submit the assignment.
Submitting:
Email your answer to <CSC151-02-grader@grinnell.edu>. The title of your email
should have the form CSC 151.02 Assignment 6: Iteration and Turtles 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.
There is no problem 1.
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)
Important: Your procedure must return the turtle to its original position and angle. Your procedure must not change the turtle's brush or color.
Hint: Use repeat. The
turtle must turn a total of 360 degrees to return to its original
angle.
For example,
(turtle-polygon! t 100 3)
(turtle-polygon! t 100 4)
(turtle-polygon! t 60 5)
(turtle-polygon! t 40 6)
Write and document procedure, (, that recursively draws a polygon with smaller polyings on the outside of each corner on the first polygin, even smaller polygons at the corners of the smaller polygons, and so on for turtle-snowflake! turtle side-length sides depth)depth levels.
Each successive level should have a side length that is 40% that of the previous level.
For example:
![]() |
(turtle-snowflake! t 100 4 2)
This call draws an inner square with edges of length 100, then at each corner places an additional square with edges of length 40. |
![]() |
(turtle-snowflake! t 100 4 4)
This call draws the same two-level image as the previous example, but adds an additional square at each corner of the squares with edge length 40. The smallest squares in this image have edges that are 16 long (40% of 40). |
![]() |
(turtle-snowflake! t 100 5 2)
Like the example with four edges and two levels, this call draws a pentagon with edges that are 100 pixels long and a smaller pentagon (edge length 40) at each corner. |
![]() |
(turtle-snowflake! t 100 5 4)
Hopefully this example makes it clearer why this procedure is called |
![]() |
(turtle-snowflake! t 100 6 4)
Adding another edge leads to some overlapping polygons in this example. While you can certainly have more than six edges or more than four levels, the drawing will take quite a while to finish. |
Your turtle-polygon! procedure may be a useful starting point, but you probably won't be able to use it directly in your implementation of turtle-snowflake!.
You may find it useful to mix iteration and recursion: use iteration to draw each side of a polygon, and recursion to draw each level.