Functional PostScript Examples [See all the examples in a single page]

Functional PostScript Examples


Right-angle Fractal

This program draws a right-angle fractal. A simple algorithm generates a very complex picture using just the very basic pt, line, and compose calls. [PostScript Output]

(define (fractal point1 point2 depth)
  (stroke (let recur ((pt1 point1) (pt2 point2) (d depth))
	    (if (= d 0) (line pt1 pt2)
		(let* ((x1 (pt:x pt1))
		       (y1 (pt:y pt1))
		       (x2 (pt:x pt2))
		       (y2 (pt:y pt2))
		       (newx (+ (/ (+ x1 x2) 2)
				(/ (- y2 y1) 2)))
		       (newy (- (/ (+ y1 y2) 2)
				(/ (- x2 x1) 2)))
		       (newpt (pt newx newy)))
		  (compose (recur pt1 newpt (- d 1))
			   (recur newpt pt2 (- d 1))))))))

FPS Home | 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