Build Image

You should learn how to use build-image to make the pictures in Chapter 15.

Advanced: build-image

The build-image uses a function that specifies the pixel color to create a rectangular image.

The first example is a function that always returns orange, so it makes an orange square:

(define (pixel-color x y)
  "orange")
(build-image 300 200 pixel-color)

Notice that pixel-color does not appear in parentheses. The build-image command needs to activate (run) the pixel-color function over and over again, so needs to know the name of the function.

The second example is to give different colors in different circumstances. This example uses a mathematical formula to make a nice picture. Try it.

(define (pixel-color-ii x y)
  (cond [(<= (abs (- y x)) 30)
         "orange"]
        [else 
         "blue"]))
(build-image 300 200 pixel-color-ii)