Fundamentals of Computer Science I (CS151.02 2007S)
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Assignment]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151 2006F (Rebelsky)]
[CSC151.01 2007S (Davis)]
[CSCS151 2005S (Stone)]
This laboratory is also available in PDF.
Summary: We explore a technique for algorithmically
generating interesting images that takes advantage of Scheme's
random
procedure.
Contents:
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 random-art.scm
.
c. In the GIMP, open a Script-Fu console and load random-art.scm
.
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 image
.
c. Enter the following sequence of commands a few times to generate a few
random
lines.
(set-fgcolor (random-color)) (random-brush) (random-line image 200 100)
a. Read through the code to determine what splat
does.
b. Use 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-blue
and random-grey
. Make sure that
you understand the strategy used for each.
d. Update splat
to that it only generates grey lines using
a different shade of grey each time. Draw a few more lines.
e. Update splat
so that it only generates blue lines using
a different shade of blue each time. Draw
a few more lines.
f. Update 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
width
and 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
splat
.
Write a procedure, (blob img width height)
that
random-ellipse
),
d. Test your procedure by drawing a few blobs on the screen.
In the previous exercise, you wrote a procedure, blob
and
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 blob
.
Write and test a procedure, (blobs img width height times)
that draws a blob on the image times times.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/History/Labs/randomized-drawing.html
.
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]
-
[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Assignment]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151 2006F (Rebelsky)]
[CSC151.01 2007S (Davis)]
[CSCS151 2005S (Stone)]
Disclaimer:
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 http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2007S/Labs/randomized-drawing.html
.
You may wish to
validate this document's HTML
;
;
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.