;;; Scheme Recursive Art Contest Entry ;;; ;;; Please do not include your name or personal info in this file. ;;; ;;; Title: <"Thallsophobia"> ;;; ;;; Description: ;;; <'Sea's darkest abyss/ You are a lifetime ago/ This a conclusion> ; TURTLE MOVEMENT (define (move-right x) (setheading 90) (forward x)) ; USEFUL PROCEDURES (define (at_index s i) (if (= i 0) (car s) (at_index (cdr s) (- i 1)) ) ) (define (len s) (define (helper s i) (if (null? s) i (helper (cdr s) (+ i 1)) ) ) (helper s 0) ) ; ==== Variables ==== (define window_width (/ (screen_width) 1)) ;so they can be treated as variables instead of calling the functions everytime (define window_height (/ (screen_height) 1)) (define c1 0) (define c2 0.8) ;input the real and imaginary parts for the complex constant c in the recurrence relation. (define (f x y c1 c2) (cons (+ (- (* x x) (* y y)) c1) (+ (* 2 x y) c2)) ) ;Specify the function f for which the julia set is computed ;Outputs a pair with first element the real part of the image and the secnd element the complex part. (define (escape_depth px py) (define x_normalization 1) (define y_normalization 1) (define x_scaled (- (/ (* (- 1 (- x_normalization)) (- px (/ (- window_width) 2))) (- (/ window_width 2) (/ (- window_width) 2)) ) x_normalization)) ; x coordinates normalized to julia set domain (define y_scaled (- (/ (* (- 1 (- y_normalization)) (- py (/ (- window_height) 2))) (- (/ window_height 2) (/ (- window_height) 2)) ) y_normalization)) ; y coordinates normalized to julia set domain (define (filled-julia depth max-depth x y) (cond ((and (< depth max-depth) (< [+ (* x x) (* y y)] 4)) (define x-new (car (f x y c1 c2))) (define y-new (cdr (f x y c1 c2))) (filled-julia (+ depth 1) max-depth x-new y-new) ) (else depth) ) ) (filled-julia 0 2500 x_scaled y_scaled) ;Run for 2500 iterations ) (define (depth_row x y) (define (iterator i window_width row x) (cond ((< i window_width) (define row (append row (list (escape_depth x y)))) (iterator (+ i 1) window_width row (+ x 1)) ) (else row) ) ) (iterator 0 window_width '() x) ) (define (render-julia) (define x_0 (/ (- window_width) 2)) (define y_0 (/ window_height 2)) (define x x_0) (define y y_0) (define (iteratorator y y_0) (cond ((> y (- y_0)) (define row (depth_row x y)) (define (iterator_2 i palette) (cond ((< i (len row)) (define j i) (define (iterator_3 j) (if (and [< j (len row)] [= (at_index row j) (at_index row i)]) (iterator_3 (+ j 1)) j ) ) (define j (iterator_3 j)) (define palette (append palette [list (list (at_index row i) (- j i))])) (if (> j i) (define i j) (define i (+ i 1)) ) (iterator_2 i palette) ) (else palette) ) ) (define palette (iterator_2 0 '())) (define (for_iter i palette) (cond ((< i (len palette)) (define offset (* 255 (- 1 (/ (log (+ [* (/ [at_index (at_index palette i) 0] 100) 150] 1)) (log 256) ) ) ) ) (define offset (quotient offset 1)) ; truncation (define r (- 255 offset)) (cond ((> r 255) (define r 230) (define g 230) (define b 230) ) (else (define r 0) (define g 0) (define b (- 255 offset)) ) ) (color (rgb (/ r 255) (/ g 255) (/ b 255))) (pendown) (move-right (at_index (at_index palette i) 1)) (penup) (for_iter (+ i 1) palette) ) (else nil) ) ) (for_iter 0 palette) (define y (- y 1)) (setposition x y) (iterator y y_0) ) ) (else nil) ) (iterator y y_0) ) (speed 0) (penup) (setposition (/ (- window_width) 2) (/ window_height 2)) (pendown) (define (draw) (render-julia) (setposition (/ window_width 13) (/ window_height 45)) (addshape) (shape) (stamp) (exitonclick)) ; Please leave this last line alone. You may add additional procedures above ; this line. (draw)