Build Image

Build-image to create images from a formula for the pixel color.

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)
Last modified August 18, 2023: 2022-2023 End State (7352e87)