(define pollock-series (lambda (n width height) (let* ((image (image-new width height)) (color (rgb-new (mod (+ 150 (mod n 256)) 200) (mod (+ 100 (mod n 256)) 200) (mod (+ 50 (mod n 256)) 200))) (vec (vector 0))) (image-show image) (let kernel ((n1 (vector-ref vec 0))) (let* ((left (+ 5 (mod (- n n1) (/ width 5)))) (top (mod (* n n1) (- height (/ height 5)))) (right (- width 5)) (bottom (- height 1)) (color (rgb-new (mod (+ 150 (mod (- n n1) 256)) 200) (mod (+ 100 (mod (- n n1) 256)) 200) (mod (+ 50 (mod (- n n1) 256)) 200)))) (context-set-fgcolor! color) (image-select-rectangle! image selection-replace (mod (+ left (mod (- n n1) (- width (/ width 5) 30))) (- width (/ width 10))) top (/ width 10) (/ height 10)) (image-fill! image) (image-select-nothing! image) (context-update-displays!) (fractal-rectangle! image color left (+ top (/ height 10)) right bottom 2 n vec) (kernel (vector-ref vec 0)) ))))) (define fractal-rectangle! (lambda (image color left top right bottom level n vec) (if (>= (vector-ref vec 0) n) (throw "Out of paint!") (cond ; Base case: We're at a level in which we just draw the rectangle. ((and (= level 0) (= color-white (color-choice image color left top right bottom)) (context-update-displays!))) ((= level 0) (vector-set! vec 0 (+ 1 (vector-ref vec 0))) (display (vector-ref vec 0)) (context-set-fgcolor! (color-choice image color left top right bottom)) (image-select-rectangle! image selection-replace left top (- right left) (- bottom top)) (image-fill! image) (image-select-nothing! image) (context-update-displays!)) ; Recursive case: Break the rectangle into a few parts and recurse ; on each. (else (let* ((midcol1 (round (+ left (/ (- right left) 3)))) (midcol2 (round (- right (/ (- right left) 3)))) (midrow1 (round (+ top (/ (- bottom top) 3)))) (midrow2 (round (- bottom (/ (- bottom top) 3))))) ; First row of squares (fractal-rectangle! image color midcol1 top midcol2 midrow1 (- level 1) n vec) (fractal-rectangle! image color left top midcol1 midrow1 (- level 1) n vec) (fractal-rectangle! image color midcol2 top right midrow1 (- level 1) n vec) ; Second row of squares (fractal-rectangle! image color midcol1 midrow1 midcol2 midrow2 (- level 1) n vec) (fractal-rectangle! image color left midrow1 midcol1 midrow2 (- level 1) n vec) (fractal-rectangle! image color midcol2 midrow1 right midrow2 (- level 1) n vec) ; Third row of squares (fractal-rectangle! image color midcol1 midrow2 midcol2 bottom (- level 1) n vec) (fractal-rectangle! image color left midrow2 midcol1 bottom (- level 1) n vec) (fractal-rectangle! image color midcol2 midrow2 right bottom (- level 1) n vec) )))))) (define color-choice (lambda (image color left top right bottom) (if (and (or (= color (image-get-pixel image (- left 1) (- top 1))) (= color (image-get-pixel image (+ right 1) (- top 1)))) (not (or (= color (image-get-pixel image (+ left 1) (- top 1))) (= color (image-get-pixel image (- left 1) (- bottom 1))) (= color (image-get-pixel image (+ right 1) (- bottom 1)))))) color color-white)))