This laboratory is also available in PDF.
Summary: We explore a technique for algorithmically
generating interesting images that takes advantage of Scheme's
a. Save a copy of
random-art.scm in your directory structure (e.g., on the Desktop).
b. Start DrScheme and open your copy of
c. In the GIMP, open a Script-Fu console and load
a. Read through
random-art.scm to make sure that you know
what all of the procedures do.
b. Create an image (say 200 wide by 100 high) and name it
c. Enter the following sequence of commands a few times to generate a few
(set-fgcolor (random-color)) (random-brush) (random-line image 200 100)
a. Read through the code to determine what
splat to generate a few additional lines.
c. As you may have noted,
random-art.scm contains two
different procedures for generating a random color in a limited range,
random-grey. Make sure that
you understand the strategy used for each.
splat to that it only generates grey lines using
a different shade of grey each time. Draw a few more lines.
splat so that it only generates blue lines using
a different shade of blue each time. Draw
a few more lines.
splat so that it only uses circular brushes.
g. Pick a few favorite brushes and update
splat so that it
selects between those brushes.
a. Write a procedure,
(random-ellipse img width height), that
selects an unpredictable eclipse in
img. (The parameters
height represent the width and height
of the image. You can use them or ignore them.)
b. Test your procedure with a sequence of commands like the following:
(define img (create-img 200 100)) (random-ellipse img 200 100) (stroke img)
c. In addition to selecting a random ellipse, we might also want
to select a random foreground color, a random background color, and
even a random brush. Rather than retyping a sequence of commands,
we might encapsulate them into a procedure, which we might call
Write a procedure,
(blob img width height) that
d. Test your procedure by drawing a few blobs on the screen.
In the previous exercise, you wrote a procedure,
then called it a few times. In practice, most programmers don't like to
type the name of a procedure again and again and again. What's the solution?
A new procedure that repatedly calls
Write and test a procedure,
(blobs img width height times)
that draws a blob on the image times times.
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 Thu Sep 13 20:54:27 2007.
The source to the document was last modified on Fri Apr 6 10:20:28 2007.
This document may be found at
You may wish to validate this document's HTML ; ;Samuel A. Rebelsky, firstname.lastname@example.org
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.