(use data-structures srfi-1) (define height 900) (define width 900) (define escape-value 700) (define (->integer n) (inexact->exact (floor (exact->inexact n)))) (define (hsb->rgb h s b) (let* ((c (* b s)) (x (* c (- 1 (abs (sub1 (modulo (->integer (/ h 60)) 2)))))) (m (- b c)) (rgb* (cond ((and (<= 0 h) (< h 60)) (list c x 0)) ((and (<= 60 h) (< h 120)) (list x c 0)) ((and (<= 120 h) (< h 180)) (list 0 c x)) ((and (<= 180 h) (< h 240)) (list 0 x c)) ((and (<= 240 h) (< h 300)) (list x 0 c)) ((and (<= 300 h) (< h 360)) (list c 0 x))))) (map (lambda (c) (->integer (* 255 (+ m c)))) rgb*))) (define (color-mapping i) (hsb->rgb (- 359 (modulo i 360)) 1 (/ i (+ 8 i)))) (define colors (map color-mapping (iota (add1 escape-value)))) (define (mandelbrod/real real img) (define (x* x y) (+ (- (* x x) (* y y)) real)) (define (y* x y) (+ (* 2 x y) img)) (let iterate ((x 0) (y 0) (count 0)) (if (or (>= (+ (* x x) (* y y)) 4) (>= count escape-value)) count (iterate (x* x y) (y* x y) (add1 count))))) (define (infinity-trap/instant-draw acorner bcorner side #!key (formula mandelbrod/real)) (let ((h-gap (/ side height)) (w-gap (/ side width))) (fprintf (current-error-port) "Gap: ~a, ~a~%" h-gap w-gap) (let loop ((i 0)) (if (>= i (* height width)) 'done (begin (let* ((c (formula (+ acorner (* w-gap (remainder i width))) (+ bcorner (* h-gap (quotient i width))))) (colors (if (>= c escape-value) '(0 0 0) (list-ref colors (->integer c))))) (printf "~a ~a ~a~%" (car colors) (cadr colors) (caddr colors))) (loop (add1 i))))))) (print "P3") (printf "~a ~a~%" width height) (print 255) (infinity-trap/instant-draw -2 -1.25 2.5 formula: mandelbrod/real)