;;; Scheme Recursive Art Contest Entry ;;; ;;; Please do not include your name or personal info in this file. ;;; ;;; Title: Hilbert Curve In Mandelbrot Set with Normalized Coloring ;;; ;;; Description: ;;; Hilbert's space-filler ;;; Fills Mandelbrot set. Outside, ;;; A coloring scheme. ;Define constants (define res 350) ;Number of pixels to draw in each direction (define max_iters 500) ;Number of iterations to check for escape ;Return the magnitude squared of a complex number R+Ii. (define (mag r i) (+ (* r r) (* i i))) ;Return the floor of the logarithm base 1.023293 (10^1/100) of a number x > 1. (define (log x cur) (if (< x 1.023293) ;If no more exponentiation is needed, return current total. cur (log (/ x 1.023293) (+ cur 1)))) ;Return (approx.) the normal log of a number x > 1. (define (log10 x) (/ (log x 0) 100)) ;Return normalized escape length of a coordinate, or #f for no escape. (define (esc_len zr zi cr ci iters) (cond ((> (mag zr zi) 100) ;If escaped, return normalized escape length. (- iters ;Subtracting this factor "smoothes" out the escape length, ;so we go from integers (which creates bands of color) ;to a smooth gradient from blue to white. (/ (log10 (/ (log10 (mag zr zi)) 2)) 0.30102999566))) ((= iters max_iters) ;If out of iterations, return #f. #f) ;If not escaped yet, iterate. (else (esc_len (+ (- (* zr zr) (* zi zi)) cr) (+ (* 2 zr zi) ci) cr ci (+ iters 1))))) ;Draw the Mandelbrot set starting at X, Y and proceeding along increasing Y, ;then increasing X. (define (mandelbrot x y) (cond ((> x res)) ;End when you've finished all the columns ;Start at next column if you've finished this one ((> y res) (mandelbrot (+ x 1) (- res))) ;Otherwise, draw a pixel of the set. (else (define real (/ (* 2 x) res)) (define imag (/ (* 2 y) res)) ;Get normalized escape length (define len (esc_len 0 0 real imag 0)) ;Draw color if not in set (if len (begin (penup) (goto x y) (pendown) ;Take the log of the escape length to flatten ;out the colors (make the fringe brighter) (define rg (/ (log10 len) (log10 max_iters))) (color_rgb (list rg rg 1)) (fd 1)) nil) ;Draw next piece (mandelbrot x (+ y 1))))) (define (draw_hilbert iter) (if (= iter 0) (lambda (orient dir) nil) (lambda (orient dir) (let ((hilbert (draw_hilbert (- iter 1))) (ninety (if dir 90 -90)) (connect (lambda (angle) (setheading (+ orient angle)) (forward 2)))) (begin (hilbert (+ orient ninety) (not dir)) (connect 0) (hilbert orient dir) (connect ninety) (hilbert orient dir) (connect 180) (hilbert (- orient ninety) (not dir))))))) (define (draw) (speed 0) (hideturtle) ;; Fill screen with white (dot 1000 'white) (penup) ;; Draw Hilbert curve in light blue (color_rgb (list 128 128 255)) (goto -350 -225) (pendown) ((draw_hilbert 8) 0 #t) ;; Draw Mandelbrot set (mandelbrot (- res) (- res)) (exitonclick)) ; Please leave this last line alone. You may add additional procedures above ; this line. All Scheme tokens in this file (including the one below) count ; toward the token limit. (draw)