previous up next     contents index
Next: Protecting Graphics Operations Up: Graphics Previous: A Basic Example

A More Complicated Example

The use of multiple viewports, viewport descriptors, drawing operations for multiple viewports is as easy as the use of a single viewport:

  > (open-graphics)
  > (let* ([w1  (open-viewport "viewport 1" 300 300)]
           [w2  (open-viewport "viewport 2" 200 500)]
           ; \var{w1} and \var{w2} are viewport descriptors for different windows

          [d1  (draw-line w1)]
          [d2  (draw-line w2)])
          ; \var{d1} and \var{d2} are functions that draw lines in different viewports

      (d1 (make-posn 100 5) (make-posn 5 100))
      ; draws a line in viewport labeled ``viewport 1''

      (d2 (make-posn 100 100) (make-posn 101 400)))
      ; draws a line in viewport labeled ``viewport 2''

  ; we no longer have access to viewports 1 and 2, 
  ; since their descriptors were local variables.

  > (close-graphics)           ; removes the viewports



PLT