Please vote for your favorite entry in this semester's 61A Recursion Exposition contest.
The winner should exemplify the principles of elegance, beauty, and abstraction that are
prized in the Berkeley computer science curriculum. As an academic community, we should strive
to recognize and reward merit and achievement.
Eligible entries contain at most 256 tokens of Scheme, not including comments or delimiters.
The Song of Ice and Fire
A fragile snowflake
Stands eternally against
An engulfing flame
The Song of Ice and Fire
Tokens: 250
(speed 0)
(bgcolor "black")
(ht)
(forward 30)
(left 90)
(forward 400)
(setheading 0)
(define (drawer r g b num_repeated in_angle out_angle mag size rr gg bb divisor divider factor) ; overarching draw function
(define num 70)
(define (repeat k fn) ; repeats functions, literally the most useful function ever
(if (> k 0)
(begin (fn) (repeat (- k 1) fn))
nil))
(define (re-caller times num in_angle rr gg bb size) ; create smaller shapes
(cond
((<= times 0))
(else
(right (/ in_angle num))
(repeat mag (lambda () (forward size) (lt (* (/ 35 divider) in_angle)))) ;creates the smaller shapes
(re-caller (- times 1) num in_angle rr gg bb size))))
(define (checker r g b in_angle rr gg bb size) ; this fucntion "checks" the master_func
(cond
((< (- g gg) 0)) ; these test for when the color is "illegal" I left a few tests out because my images don't involve them
((> (- g gg) 1)
(master_func r g b in_angle rr 0 (- 0.05) size))
((> (- b bb) 1))
((< (- size factor) 0)) ; makes sure the size doesn't get too big/ too small
(else
(master_func r g b in_angle rr gg bb size))))
(define (master_func r g b in_angle rr gg bb size) ;this is just used to save space, loops stuff
(color (eval(rgb r g b)))
(re-caller (/ num (/ 35 divisor)) num in_angle rr gg bb (- size factor))
(checker (- r rr) (- g gg) (- b bb) in_angle rr gg bb (- size factor)))
; these color "capturing" calls are placed here because this is dictates the larger shapes, rather than each individual line
(repeat num_repeated (lambda () (right out_angle) (checker r g b in_angle rr gg bb size))) ; creates the LARGER shape, ie hexagon
)
(define (draw) ; I only have this function because calling (exitonclick) is easier. Waste of tokens but oh well :p
(left 4.5)
(drawer 0.59 0.89 0.99 11 60 120 3 175 0.03 0.045 0 1 1 1) ;ice
(penup)
(setheading 90)
(forward 425)
(setheading 180)
(backward 280)
(setheading 0)
(left 3)
(pendown)
(drawer 0.99 0 0 1 97 96.85 5 550 0 (- 0.05) 0 3 2 10) ;fire
(exitonclick))
(draw)
These falling fractals
Impossible yet here,
So quiet, so cold
Snow in California
Tokens: 143
(define (shp l d)
(pendown)
(cond
((= d 0) (fd l))
(else (draw l d))
)
)
(define (draw l d)
(shp (/ l 3) (- d 1))
(lt 60)
(shp (/ l 3) (- d 1))
(rt 120)
(shp (/ l 3) (- d 1))
(lt 60)
(shp (/ l 3) (- d 1))
)
(define (sn l d s)
(cond
((= 0 s) (penup))
(else (shp l d) (rt 72) (sn l d (- s 1)))
)
)
(define (circ s dp hd n)
(cond
((not (= 0 dp))
(color (cc n))
(sn s hd 5)
(right 30)
(fd (/ s 2.5))
(if (= (modulo dp 2) 0)
(circ (/ s 1.75) (- dp 1) (- hd 1) (- n 1))
(circ (/ s 1.75) (- dp 1) hd (- n 1))
)
)
)
)
(bg "#000000")
(hideturtle)
(speed 0)
(penup)
(goto -220 -180)
(circ 350 9 4 7)
Rainbow galaxies
A Recursive Collision
Take Astro C10
Rainbow Galaxies
Tokens: 139
(define (spiral n times r g b)
(cond ((< n times)
(cond ; Set the rgb color
((and (> r b) (= g 0) (< b 0.98)) (define b (+ b 0.02)))
((and (> r 0.05) (= g 0)) (define r (- r 0.02)))
((and (< g 0.98) (< r .1)) (define g (+ g 0.02)) (define r 0))
((> b 0.05) (define b (- b 0.02)))
((< r 0.98) (define r (+ r 0.02)) (define b 0))
((> g 0.05) (define g (- g 0.02)))
(else (define g 0)))
(color (rgb r g b))
(fd (* .83 n))
(rt 89)
(spiral (+ n 1) times r g b))))
(define (draw)
(hideturtle)
(bgcolor (rgb 0 0 0))
(speed 0)
(spiral 1 386 1 0 0)
(spiral 1 299 0 1 0)
(spiral 1 150 0 0 1)
(spiral 1 100 1 0 0))
(draw)
I wished to draw a
bear, but that required effort
this happened instead
Polygons
Tokens: 371
(speed 0)
(width 1.5)
(pencolor "#FDB515")
(fillcolor "#004080")
(ht)
(define (cadr s) (car (cdr s)))
(define (setp x)
(setposition (car x) (cadr x))
)
(define (coolsquare a b c d p x bool)
(if (not (= x 60))
(begin
(begin_fill)
(draw a b c)
(setp d)
(setp a)
(end_fill)
(coolsquare
(changeco a b p)
(changeco b c p)
(changeco c d p)
(changeco d a p)
p (+ x 1) (- 1 bool))
))
)
(define (draw a b c)
(penup)
(setp a)
(pendown)
(setp b)
(setp c)
)
(define (changeco a b p)
(cons
(+ (* (car a) p) (* (car b) (- 1 p)))
(cons (+ (* (cadr a) p) (* (cadr b) (- 1 p)))
nil))
)
(define (cooltri a b c p x bool)
(if (not (= x 27))
(begin
(begin_fill)
(draw a b c)
(setp a)
(end_fill)
(cooltri
(changeco a b p)
(changeco b c p)
(changeco c a p)
p (+ x 1) (- 1 bool))
))
)
(define (fun1 l a b c)
(define h (calcshift a b))
(define g (calcshift a c))
(define (fun2 z m)
(if (< m 4)
(begin (define w (shift z (list (* m 300) (* l -300)))) (cooltri w (shift w h) (shift w g) .9 1 1)
(fun2 z (+ m 1))))
)
(fun2 a 0)
(if (< l 2) (fun1 (+ l 1) a b c))
)
(define (fun3 l a b c d)
(define h (calcshift a b))
(define g (calcshift a c))
(define f (calcshift a d))
(define (fun4 z m)
(if (< m 4)
(begin (define w (shift z (list (* m 300) (* l -300)))) (coolsquare w (shift w h) (shift w g) (shift w f) .93 1 1)
(fun4 z (+ m 1))))
)
(fun4 a 0)
(if (< l 2) (fun3 (+ l 1) a b c d))
)
(define (shift a b)
(list (+ (car a) (car b)) (+ (cadr a) (cadr b))))
(define (calcshift a b)
(list (- (car b) (car a)) (- (cadr b) (cadr a))))
(fun3 0 '(-450 200) '(-300 350) '(-150 200) '(-300 50))
(fun1 0 '(-450 200) '(-450 350) '(-300 350))
(fun1 0 '(-450 200) '(-450 50) '(-300 50))
(fun1 0 '(-150 200) '(-150 350) '(-300 350))
(fun1 0 '(-300 50) '(-150 200) '(-150 50)))