Media Scripting in Scheme
Summary: In this assignment, you will experiment with drawings in which many straight lines are used to give the appearance of curved shapes. The technique for making this drawings is based on the idea of string art.
Purposes: To give you more experience with numeric recursion. To give you an opportunity to play with interesting images.
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.
Email your answer to
<firstname.lastname@example.org>. The title of your
email should have the form
MediaScheme: String Art
and should contain your answers to all parts of the assignment.
Scheme code should be in the body of the message. Do not
attach any images. We should be able to regenerate any
images you create just from the instructions you submit.
Warning: So that this assignment is a learning experience for everyone, I may spend class time publicly critiquing your work.
Many of you may have played with string art when you were growing up. In this technique, colored string is wrapped around pegs or notches on a board to produce geometric or other figures that give the illusion of curves, even though the string is pulled in straight lines. Our goal here is to simulate this technique using Scheme procedures.
In string art,
the endpoints of the individual lines form the edges of the figure.
We will limit ourselves (at first) to drawing figures whose edges are
horizontal and vertical lines, that is, rows and columns.
We will allow the user to specify
n, the number
of lines that are drawn, and use numeric recursion to draw them.
The user should also be able to specify the position and size of the
figure; we do this with four parameters:
along which the ends of the lines will fall,
of the figure.
Read the following procedure. What is the base case? What is the simplification step? How are the two endpoints of each line computed?
;;; Procedure: ;;; image-string-art! ;;; Parameters: ;;; image, an image ;;; n, a positive integer ;;; edge-col, an integer ;;; edge-row, an integer ;;; width, an integer ;;; height, an integer ;;; Purpose: ;;; Draw a "string art" figure. ;;; Produces: ;;; Nothing. Called for its side effects. ;;; Preconditions: ;;; No additional. ;;; Postconditions: ;;; n lines have been drawn. ;;; The lines have endpoints falling along ;;; edge-col and edge-row. ;;; The lines are evenly spaced. ;;; The lines cross each other. ;;; The figure is bounded by the rectangle ;;; (edge-col, edge-row) ;;; (edge-col + width, edge-row + height) (define image-string-art! (lambda (image n edge-col edge-row width height) (let ((col-spacing (/ width (- n 1))) (row-spacing (/ height (- n 1)))) (let kernel ((i 0)) (cond ((< i n) (let ((col1 edge-col) (row1 (+ edge-row (* (- n 1 i) row-spacing))) (col2 (+ edge-col (* i col-spacing))) (row2 edge-row)) ;(print (list col1 row1 col2 row2)) ; for debugging (image-draw-line! image col1 row1 col2 row2)) ;(context-update-displays!) ; for debugging (kernel (+ i 1))))))))
Now, try the procedure out.
(define canvas (image-new 200 200))
(context-set-brush! "Circle (01)")
(image-string-art! canvas 20 100 100 100 100)
To help you understand how the procedure works, uncomment the lines marked with comments as “for debugging”. Then try the above example again. You should be able to see the lines being drawn one by one.
Now, let's think about how to vary the parameters to the
For each of the following,
first consider what you think will happen when we make the change and
then check your answer experimentally. In each case, assume that the
change is from the original call to
You will want to clear the image or change the foreground color
after each experiment so that you can see what changed.
What will happen if we change the edge column to 0?
What will happen if we change the width to 25 and the height to 200?
What will happen if we use a negative width or height?
What will happen if we change
to 50? to 5?
Using your own version(s) of
generate three interesting 512x512 images. Each image should be created
using multiple calls to
related procedures. You may even want to write your own procedure that
uses numeric recursion to draw multiple copies of a figure that form a
How might you vary the procedures? You could change the foreground color or brush for each iteration. You could draw multiple lines for each iteration or vary the lengths or positions of the lines. You may wish to experiment with techniques similar to those you used in the lab on geometric art. There are many options.
We strongly recommend that you get some simple variations working before trying something more complicated. Think about how you can make (and test!) your changes in small steps.
For each image, write a short paragraph explaining the techniques you've used to construct the image.
In assessing your assignments, we will emphasize the modifications you have made to the code. We will consider whether these modifications were interesting and subtle, or relatively straightforward. We will also assess assignments based on our impressions of the images and corresponding paragraphs.
In our version of
image-string-art!, the two edges
of the string art figure are constrained to be a horizontal line (a row)
and a vertical line (a column).
For extra credit, write a more general version of the
image-string-art! procedure for which the two edges
are two arbitrary lines.
Or, develop a string art procedure for another shape such as an ellipse
You will need to choose appropriate parameters for the procedure.
This extra credit opportunity is open-ended; you may turn in the extra credit after this assignment is due.
Copyright (c) 2007-2009 Janet Davis, Matthew Kluber, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials copyright by John David Stone and Henry Walker and used by permission.)
This material is based upon work partially supported by the National Science Foundation under Grant No. CCLI-0633090. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
This work is licensed under a Creative Commons
Attribution-NonCommercial 2.5 License. To view a copy of this
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.