&drawings-prefix;A Procedure is Worth a Thousand Images Due: &drawings-due; Summary: In this assignment, you will further explore the design of procedures for the Gimp to draw simple pictures and how you might parameterize those pictures. Purposes: To give you further experience with files and with drawing. To help you think more about parameters. 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 &grader-email;. The title of your email should have the form &drawings-subject; 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.
Preliminaries One of the advantages of scripting simple images is that you can parameterize those images; drawing different images based on different choices. For example, a procedure that draws a face might take as parameters the roundness of the face, the color of the eyes, and the type of hair. In some situations, it is equally interesting to make the parameters control aspects of the image, but in a less obvious way. For example, one might take a number as a parameter to the face-drawing routine and use that number to determine the type of hair. (The programmer might reveal the translation of number to hair type to the client, or may leave it as a secret.)
Assignment In this assignment, you will write the latter kind of parameterized drawing procedure. In particular, you should write a procedure, (create-drawing filename val1 val2 val3), that stores in the file named by filename a drawing that is based on val1, val2, and val3, each of which is a number between 0 and 9. This drawing files should have the form from the previous assignment. That is, each line of the file should be one of the basic drawing objects followed by color, brush (in some cases), and other parameters. Once this procedure is available, you can then easily draw random pictures by selecting random values for the parameters. We recommend that you choose a relatively straightforward category of image, such as a building or a cartoonish face.
Potentially Helpful Hints There are a number of ways to convert numbers to aspects of your drawing. For example, if your drawing is of a face, you can use the first number to specify the width of the face with something like the following: (let ((face-height 120) (face-width (+ 100 (* val1 4)))) ...) It is possible to use the number to select between different categorical values, such as eye colors. (define eyecolors (list color.blue color.green color.color.copper color.grey color.brown color.dim-grey color.steel-blue color.pale-blue color.dark-brown color.very-dark-brown)) (let ((eyecolor (list-ref eyecolors val2))) ...) It is even possible to use one value to modify two different attributes. For example, in the following, val3 is used to select both the brush used to draw the hair and the kind of hair drawn. Since there are five different brushes and two kinds of hair, each different number gives a different kind of hair. (define hair-brushes (list "Calligraphic Brush" "Circle (03)" "Circle (05)" "Circle Fuzzy (03)" "Felt Pen")) ... (set-brush (list-ref hair-brushes (modulo val3 5))) (if (< val3 5) (draw-curly-hair) (draw-straight-hair))
Important Evaluation Criteria Our first question will be whether or not your code will successfully generate 1000 different images. (That is, you should ensure that each different set of parameters will, in fact, generate a different image.) Our second question will be how creatively you use these various parameters. We will also consider common coding criteria, such as clarity, elegance, and efficiency.
Appendix: Reading and writing objects To read and write object files, you may use your own solution to the previous assignment, or you may use the following lengthy but fairly straightforward solution.