# Laboratory: Geometric Art

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

## Preparation

a. Make a copy of geometric-art-lab.rkt.

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

c. Set the brush to something relatively simple and small.

> (context-set-brush! "2. Hardness 100" 2)


## Exercises

### Exercise 1: 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. Add a parameter, func, which is a function that takes one numeric parameter and produces a numeric result. Revise the procedure so that it calls func in place of sin.

c. Use draw-func-with-parallel-lines! to “graph” the cosine function.

d. Use draw-func-with-parallel-lines! to “graph” the sum of sine and cosine.

e. Use draw-func-with-parallel-lines! to graph a function of your choice.

f. 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 2: Drawing Parallel Lines with Different Brush Sizes

In the reading, we considered how one might use different brush sizes 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-thicknesses!
(lambda (image brush-sizes 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 might be in the procedure.

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

> (define some-brush-sizes
(list 1 3 5 7 9 11))
> (draw-parallel-lines-with-many-thicknesses!
canvas some-brush-sizes 12
10 10 100 10
0 15)


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

### Exercise 3: 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! "2. Hardness 075" 1)
> (draw-geometric-progression! new-canvas 5 10 190 80 0.5 2)
> (context-update-displays!)


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! "2. Hardness 075" 1)
> (draw-geometric-progression! new-canvas 5 10 190 80 0.4 2)
> (context-update-displays!)


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! "2. Hardness 075" 1)
> (draw-geometric-progression! new-canvas 5 10 190 80 0.75 2)
> (context-update-displays!)


### Exercise 4: 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 5: 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 or for-each, 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.

## Explorations

### 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!.