;;; Scheme Recursive Art Contest Entry ;;; ;;; Please do not include your name or personal info in this file. ;;; ;;; Title: Tree Recursion, Literally ;;; ;;; Description: ;;; ;;;;;;;;;;;;;;;; ;; COLORS ;; ;;;;;;;;;;;;;;;; (define tree-green "#38c94e") (define tree-brown "#4d2906") (define sky-colors '("#701da8" "#812293" "#92287f" "#a32d6a" "#b53356" "#c63942" "#d73e2d" "#e84419") ) (define mountain-color-1 '("#116e73" "#217e83")) (define mountain-color-2 '("#6f4d05" "#7f5d15")) (define sunset-color "#ff6730") ;;;;;;;;;;;;;;;;;;;;;; ;; HELPER FUNCTIONS ;; ;;;;;;;;;;;;;;;;;;;;;; ;; returns the angle from horizontal given a line (define (convert-angle x1 y1 x2 y2) (let ((dx (- x2 x1)) (dy (- y2 y1))) (if (= dx 0) (if (>= dy 0) 0 180) (degrees (atan (/ dy dx))) ) ) ) ;; compute distance of a line (define (convert-distance x1 y1 x2 y2) (let ((dx (- x2 x1)) (dy (- y2 y1))) (sqrt (+ (* dx dx) (* dy dy))) ) ) (define (cadr list) (car (cdr list))) ;;;;;;;;;;;;;;;;;;;;;;; ;; PRIMITIVE DRAWING ;; ;; FUNCTIONS ;; ;;;;;;;;;;;;;;;;;;;;;;; ;; draw a thick line at position and orientation of the turtle (define (draw-line distance thickness pen-color) ;; orient the pen (let ((half-width (quotient thickness 2))) (pendown) (color pen-color) (begin_fill) ;; center rectangle (left 90) (forward half-width) (right 90) ;; begin drawing rectangle (forward distance) (right 90) (forward thickness) (right 90) (forward distance) (right 90) (forward thickness) ;; set the pen back to starting position (backward half-width) (right 90) ;; finish up (end_fill) (hideturtle) (penup) ) ) ;; draw a mountain with shadows (define (draw-mountain base height shape-color) (let ((half-base (quotient base 2)) (fourth-base (quotient base 4)) (half-angle (convert-angle 0 0 (quotient base 2) height)) (fourth-angle (convert-angle 0 0 (quotient base 4) height)) (half-hypotenuse (convert-distance 0 0 (quotient base 2) height)) (fourth-hypotenuse (convert-distance 0 0 (quotient base 4) height))) ;; position turtle (right 90) (forward half-base) ;; start drawing (color (car shape-color)) (pendown) (begin_fill) (right 180) (forward base) (right 180) (left half-angle) (forward half-hypotenuse) (end_fill) (backward half-hypotenuse) ;; second triangle (right half-angle) (forward base) (right 180) (color (cadr shape-color)) (begin_fill) (forward fourth-base) (right fourth-angle) (forward fourth-hypotenuse) (end_fill) (penup) (setheading 0) ) ) ;;;;;;;;;;;;;;;;;;;;;; ;; DRAW THE TREE!!! ;; ;;;;;;;;;;;;;;;;;;;;;; (define (draw-tree size thickness divisions deepness angle green-by) (let ((trunk-height (quotient size divisions)) (trunk-color (if (or (<= deepness green-by) (<= divisions 1)) tree-green tree-brown))) (forward trunk-height) (if (and (> thickness 1) (> (- size trunk-height) 0) (> divisions 1) (> deepness 1)) (let ((new-size (quotient size 2)) (new-thickness (+ (quotient thickness 3) 1)) (new-divisions (+ (quotient divisions 2) 1)) (new-deepness (- deepness 1)) (new-angle (+ (quotient angle 2) 5))) ;; draw left branch (left angle) (draw-tree new-size new-thickness new-divisions (- deepness 1) new-angle green-by) (right angle) ;; draw right branch (right angle) (draw-tree new-size new-thickness new-divisions (- deepness 1) new-angle green-by) (left angle) ;; draw tree above (draw-tree (- size trunk-height) (- thickness 1) (- divisions 1) deepness (- angle 10) green-by) ) ) (backward trunk-height) ;; draw current trunk (draw-line trunk-height thickness trunk-color) ) ) (define (draw) ;; setup drawing (speed 0) (penup) ;; background (forward 400) (left 90) (forward 1000) (right 180) (map (lambda (color) (draw-line 2000 100 color) (right 90) (forward 100) (left 90) ) sky-colors) ;; sun (setposition -50 -200) (color sunset-color) (pendown) (begin_fill) (circle 100) (end_fill) (penup) ;; mountain 1 (setposition -300 -500) (setheading 0) (draw-mountain 800 400 mountain-color-1) ;; mountain 2 (setposition 150 -500) (draw-mountain 1000 500 mountain-color-2) ;; bigger tree (setposition 200 -300) (draw-tree 700 35 8 4 60 2) ;; smaller tree (setposition -300 -300) (draw-tree 300 10 5 5 40 3) ;; finish up (exitonclick)) ; Please leave this last line alone. You may add additional procedures above ; this line. (draw)