Functional PostScript Examples

Functional PostScript Examples


Bounding Box

This program draw various arcs and their bounding boxes. It demonstrates the use of the arc and bounding-box procedures. [PostScript Output]

(define arc-bounding-box
  (with-attrib ((:line-width 0.01) (:color (rgb 1 1 1)))
     (let* ((square (stroke (rect (pt 0 0) 1 1)))
	    (circle (stroke (arc  (pt 1/2 1/2) 1/2 0 2pi)))
	    (fill-c (rgb 0 0 1))
	    (arc-c  (rgb 1 1 0))
	    (draw-one     
	     (lambda (start end)
	       (let* ((a   (stroke (arc (pt 1/2 1/2) 1/2 start end)
				   (:color arc-c) (:line-width 0.04))))
		 (compose (fill (bounding-box->rect (bounding-box a))
				(:color fill-c))
			  circle square a))))
	    (draw-four      
	     (lambda (start)
	       (let lp ((n 0))
		 (if (= n 4)
		     the-empty-pict
		     (compose (draw-one start (+ start (* n 1/2pi) 1/4pi))
			      (translate 0 1.5 (lp (+ n 1)))))))))
       (lambda ()
	 (compose 
	  (fill (rect (pt 0 0) (inch 8.5) (inch 11)))
	  (translate 109 144
		     (scale 72 72
			    (let lp ((start 0))
			      (if (>= start 2pi)
				  the-empty-pict
				  (compose (draw-four start)
					   (translate 1.5 0
						      (lp (+ start 
							     1/2pi)))))))))))))


FPS Home | Prev Example | Next Example

FPS Examples: Right-angle Fractal | Arrow Fractal | Headlines | Clipping Message | Turkey Bitmap | Sun | Bounding Box | Morphing Square to Circle | Text Along a Circle | Demo Driver