Functional PostScript Examples

Functional PostScript Examples


Morphing Square to Circle

This program "morphes" a square to a circle in n steps. It demonstrates the use of tangent-arc procedure and the dash attribute. [PostScript Output]

(define square-to-circle
  (let ((draw-one (lambda (r c)
		    (let ((a (tangent-arc (pt 36 0) (pt 36 36) (pt 0 36) r)))
		      (stroke (close-path (link a
						(rotate 1/2pi a)
						(rotate pi a) 
						(rotate 3/2pi a)))
			      (:color c)
			      (:line-width 3)
			      (:dash-pattern '#(4 3)))))))
    (lambda (n)
      (translate (inch 1) (inch 5)
		 (let ((c-step (/ 1 n))
		       (r-step (/ 36 n))
		       (h-step (/ (inch 8) n)))
		   (let lp ((n n) (r 36) (c (rgb 1 0 0)))
		     (if (= n 0)
			 the-empty-pict
			 (compose (draw-one r c)
				  (translate h-step 0
					     (lp (- n 1) 
						 (- r r-step)
						 (rgb (- (rgb:r c) c-step)
						      (+ (rgb:g c) c-step)
						      0)))))))))))

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