CSC151.02 2010S Functional Problem Solving : Labs

Geometric Art

Summary: In this laboratory, you will further explore the techniques for making geometric images.


a. Create a new 200x200 image and call it canvas.

b. Make a copy of geometric-art-lab.scm.


Exercise 1: Exploring Examples

a. Test each of the two basic procedures from the reading: draw-three-parallel-lines! and draw-circle!. (Remember: You may need to call context-update-displays! after drawing.)

b. Look at each of the examples in the introduction to the corresponding reading, predict what you think the example code will do, and then run the example in MediaScript.

c. The reading provides four procedures that draw parallel lines (with some variation between them), draw-parallel-lines!, draw-colored-parallel-lines!, draw-sin-with-parallel-lines!, and draw-parallel-lines-with-decreasing-spacing!. Make sure you understand what each of the procedures is supposed to do, and then try using each with two different sets of parameters.

Exercise 2: Drawing Functions, Revisited

a. Make a copy of draw-sin-with-parallel-lines! and rename it draw-func-with-parallel-lines!. Make sure that this renamed copy still works.

b. Revise the procedure to graph cosine, rather than sine.

c. Revise the procedure to graph the sum of sine and cosine, rather than the sine (or cosine).

d. Revise the procedure to graph a function of your choice.

e. Revise the function so that it draws each line in a different color (based on the column of the line or the height of the line, as you choose).

Exercise 3: Drawing Parallel Lines with Different Brushes

In the reading, we considered how one might use different brushes for neighboring parallel lines, but never finished the procedure to do that. Here's a header for that procedure.

(define draw-parallel-lines-with-many-brushes!
  (lambda (image brushes n start-col start-row end-col end-row hoff voff)

a. Finish writing the procedure. You should look at the definition of some of the other parallel line procedures (such as draw-parallel-lines!) to figure out what belongs.

b. What do you expect the following call to generate?

> (define some-brushes 
    (list "Circle (01)" "Circle (03)" "Circle (05)" 
          "Circle (07)" "Circle (09)" "Circle (11)"))
> (draw-parallel-lines-with-many-brushes!
    canvas some-brushes 12
    10 10 100 10 
    0 15)

c. Check your answer experimentally.

d. Extend the procedure so that it varies both color and brushes.

Exercise 4: Decreasing Spacing, Revisited

In the reading, we explored a procedure in which each space between lines is half of the space between lines to the left. Some callers might prefer to have a different ratio, such as 3/4 or 1/3. Let's rewrite the procedure to permit the caller to specify that parameter, which we'll call ratio. Here's the start of the new procedure, with a somewhat shorter name.

(define draw-geometric-progression!
  (lambda (image col start-row end-row spacing ratio close-enough)

a. Write that procedure.

b. What do you expect the following set of instructions to do?

> (define new-canvas (image-new 200 200))
> (image-show new-canvas)
> (context-set-brush! "Circle (01)")
> (draw-geometric-progression! new-canvas 5 10 190 80 0.5 2)
> (context-update-displays!)

c. Check your answer experimentally.

d. Consider the following variant of the previous instructions, using a smaller ratio. How do you expect the generated image to differ?

> (define new-canvas (image-new 200 200))
> (image-show new-canvas)
> (context-set-brush! "Circle (01)")
> (draw-geometric-progression! new-canvas 5 10 190 80 0.4 2)
> (context-update-displays!)

e. Check your answer experimentally.

f. Consider the following variant of the previous instructions, using a larger ratio. How do you expect the generated image to differ?

> (define new-canvas (image-new 200 200))
> (image-show new-canvas)
> (context-set-brush! "Circle (01)")
> (draw-geometric-progression! new-canvas 5 10 190 80 0.75 2)
> (context-update-displays!)

g. Check your answer experimentally.

Exercise 5: Decreasing Spacing, Re-Revisited

As you probably discovered in the final problem of the previous exercise, if the caller isn't careful, the final lines in the progression are drawn off the side of the image.

a. Update draw-geometric-progression! so that it stops for two reasons: the spacing is less than or equal to close-enough (as before) or the line to be drawn is outside the right-hand boundary of the image.

b. While draw-geometric-progression! is designed for progressions in which the spacing between subsequent lines decreases, we should also be able to make it draw progressions in which the spacing increases. Write instructions for generating a sequence of lines in which the first line appears in column 3, the next in column 5 (spacing of 2), the next in column 9 (spacing of 4), the next in column 17 (spacing of 8), and the spacing continues to double.

Exercise 6: Concentric Circles

In the introduction to the corresponding reading, after drawing three parallel lines, we then generalized that technique. However, although we drew three concentric circles, we never generalized that technique.

a. Write a procedure, (draw-bullseye! image n col row outer-radius delta-radius), that draws a sequence of n concentric circles, all with the same center, in which the outermost circle is radius of outer-radius and each subsequent circle has a radius that is delta-radius smaller.

b. As we saw in the reading, it can also be interesting to draw a sequence of circles that do not share a center, but have a progression of centers as well as a progression of smaller radii. Write a procedure, (draw-circle-sequence! image n col row radius d-col d-row d-radius), that draws a sequence of n circles, the first of which is centered at (col,row) with radius radius, and each subsequent one has the column offset by d-col, row offset by d-row, and radius offset by d-radius.

c. Rewrite draw-bullseye! so that its body is a call to draw-circle-sequence!.

For Those With Extra Time

You need not do the extra problems in order. Read through them and decide which is most worth your time.

Extra 1: Drawing Parallel Lines Without Explicit Recursion

In the corresponding reading, we wrote a procedure, draw-parallel-lines!, using direct recursion. It is also possible to write this procedure using a clever combination of map, iota, and an anonymous function. Try rewriting draw-parallel-lines! using this strategy.

Extra 2: Sequences of Circles with Common Edges

Consider a function, (draw-left-bounded-circles! image n col row radius delta-radius), that draws n circles, each of which has a left edge at column col, the outermost circle has radius radius and each subsequent circle has a radius that is delta-radius smaller than the previous circle.

a. Write this procedure using direct recursion.

b. Can you write this procedure with a call to draw-circle-sequence!? Why or why not?

Extra 3: Sequences of Circles with Variation

Rewrite draw-circle-sequence! so that it adds some interesting variant. It might draw the circles in different colors, using a nonlinear offset of radii or centers, or anything else you deem appropriate.


Exploration 1: Your Own Images

Create an image that you find aesthetically appealing with a few calls to one of the variants of draw-parallel-lines!. You should feel free to change brush and foreground color between calls.

Exploration 2: Robert Delaunay

A number of artists have created interesting images using concentric circles and other geometric shapes. One of the more famous is French artist Robert Delaunay. Find a few of Delaunay's works and see if you can make something that resembles a portion of a work using a variant of draw-circle-sequence!.

Creative Commons License

Samuel A. Rebelsky,

Copyright (c) 2007-10 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 license, visit or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.