Saturday, August 3, 2013

Circle Fractal using DrRacket

1:  (require 2htdp/image)  
2:    
3:    
4:  ;; =================  
5:  ;; Constants:  
6:    
7:  (define STEP (/ 2 5))  
8:  (define TRIVIAL-SIZE 5)  
9:    
10:  ;; Funtions  
11:    
12:  ;; Number -> Image  
13:  ;; produce the above fractal of the given size  
14:  (check-expect (circle_frac TRIVIAL-SIZE) (circle 5 "solid" "darkgreen"))  
15:  (check-expect (circle_frac (* (/ 5 2) TRIVIAL-SIZE))  
16:         (local [(define sub (circle 5 "solid" "darkgreen"))]  
17:          (above sub  
18:              (beside sub (circle (* (/ 5 2) TRIVIAL-SIZE) "solid" "darkgreen") sub)  
19:              sub)))  
20:    
21:    
22:  ;(define (circle_frac s)      ;stub  
23:  ; (square 0 "solid" "white"))  
24:    
25:  (define (circle_frac s)  
26:   (if (<= s TRIVIAL-SIZE)  
27:     (circle s "solid" "darkgreen")  
28:     (local [(define sub (circle_frac (* STEP s)))]  
29:      (above sub  
30:          (beside sub (circle s "solid" "darkgreen") sub)  
31:          sub))))  
32:    
33:    
34:    

No comments:

Post a Comment

Linguistics and Information Theory