CSC151 2010S, Class 34: Geometric "Art" Through Numeric Recursion Overview: * Questions (Numeric Recursion; Geometric "Art"; Life, the Universe, and Everything) * Unclear Answers * Lab Admin: * Reading for tomorrow: Characters and Strings. * We may have prospectives on Friday. Fun fun fun! (If you object to using class time to annoy prospies, we can skip the fun.) * Three stories about The Advisee (if you want them). * EC for Today's CS and Disability talk (4:30 in Science 3821). * EC for Wednesday's CS and Disability talk (4:15 in JRC101). * EC for Thursday's convocation. * EC for Thursday's "Teaching Millenials" CS Extra (4:30 in Science 3821). * EC for Friday's "Computational Games" CS Extra (noon in Science 3821; Free Pizza; I'll need an approximate count on Wednesday). * I will strive to make the rest of today a "Sam just answers questions" day. ;;; Procedure: ;;; cname->rgb-list ;;; Parameters: ;;; cname, a color name ;;; Purpose: ;;; Determine the components of the RGB color that ;;; corresponds to cname. ;;; Produces: ;;; components, a list of three integers, each in the ;;; range 0-255. ;;; Preconditions: ;;; cname must be a valid color name, that is ;;; (color-name? cname) is #t ;;; Postconditions: ;;; components is a list of three integers, (r g b) ;;; 0 <= r < 256 ;;; 0 <= g < 256 ;;; 0 <= b < 256 ;;; (rgb->color-name (rgb-new r g b)) = cname (define cname->rgb-list (o rgb->rgb-list color-name->rgb)) ;;; Procedure: ;;; c ;;; Parameters: ;;; cnames, a list of color names ;;; Purpose: ;;; Count colors with dominant components ;;; Produces: ;;; stuff, a list of four numbers, (x y z q) ;;; Preconditions: ;;; ;;; Postconditions: ;;; x is the number of colors in cnames in which red dominates ;;; y is the number of colors in cnames in which green dominates ;;; z is the number of colors in cnames in which blue dominates ;;; q is the number of colors in cnames in which no color dominates (define count-dominant-components (lambda (cnames) (if (null? cnames) (cons 0 (cons 0 (cons 0 (cons 0 null)))) (let* ((x (count-dominant-components (cdr cnames))) ; x is a list of four integers (components (cname->rgb-list (car cnames))) (red (car components)) (green (cadr components)) (blue (caddr components)) (r (car x)) (g (cadr x)) (b (caddr x)) (z (cadddr x))) ; if the red component of the first value is the ; largest of the three components (cond ((> red (max green blue)) ; Add one to the first element of x (list (+ 1 r) g b z)) ; if green is the largest of the three components ((> green (max red blue)) (list r (+ 1 g) b z)) ((and (> blue red) (> blue green)) (list r g (+ 1 b) z)) ; If at least two components are the same (else (list r g b (+ 1 z))))))))