#!/usr/bin/guile \ -e main -s !# (import (srfi srfi-28)) (define (mandelbrot f top-left bottom-right step max-iter) (define (mb c) (do ((i 0 (1+ i)) (z 0 (f z c))) ((or (<= max-iter i) (> (magnitude z) 2)) (write-char (integer->char i))))) (display (format "P5 ~a ~a ~a " (inexact->exact (/ (real-part (- bottom-right top-left)) step)) (inexact->exact (/ (imag-part (- top-left bottom-right)) step)) max-iter)) (do ((y (imag-part top-left) (- y step))) ((<= y (imag-part bottom-right))) (do ((x (real-part top-left) (+ x step))) ((>= x (real-part bottom-right))) (mb (make-rectangular x y))))) (define (main args) (mandelbrot (lambda (z c) (+ (* z z) c)) -2+1i +1-1i 1/1000 16))