This homework assignment is also available in PDF.
Summary: In this assignment, you will further explore the design of Script-Fu procedures for the GIMP and how you might parameterize those pictures.
Purposes: To give you further experience with Script-Fu. To help you think about parameterization.
Expected Time: One to two hours.
Collaboration: You may work in a group of any size between one and four, inclusive. You may consult others outside your group, provided you cite those others. You need only submit one assignment per group.
Submitting: Email me your work, using a subject of CSC151 Homework 11.
Warning: So that this exercise is a learning assignment for everyone, I may spend class time publicly critiquing your work.
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.)
In this assignment, you will write the latter kind of parameterized
drawing procedure. In particular, you should write a procedure
(draw-something val1 val2 val3)
that takes three integers in the range 0-9 as parameters and draws
different versions of the image based on the value of those parameters.
Once this procedure is available, you can then easily draw
pictures by selecting random values for the parameters.
(draw-something (random 10) (random 10) (random 10))
We recommend that you choose a straightforward category of image, such as a cartoonish face or a house.
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 BLUE GREEN COPPER GREY BROWN DIM_GREY STEEL_BLUE PALE_BLUE DARK_BROWN 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))
Tuesday, 23 October 2006 [Samuel A. Rebelsky]
I usually create these pages
on the fly, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Wed Aug 29 08:59:27 2007.
The source to the document was last modified on Sun Jul 29 16:12:59 2007.
This document may be found at
You may wish to validate this document's HTML ; ;Samuel A. Rebelsky, email@example.com
http://creativecommons.org/licenses/by-nc/2.5/or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.