;;; File: ;;; hop-lab.scm ;;; Authors: ;;; Janet Davis ;;; Samuel A. Rebelsky ;;; Jerod Weinman ;;; YOUR NAME HERE ;;; Summary: ;;; Starting code for the lab on higher-order procedures. ; +----------+----------------------------------------------------------------- ; | Provided | ; +----------+ ;;; Value: ;;; colors-rainbow ;;; Type: ;;; List of colors ;;; Contains: ;;; A list of colors of the rainbow. (define colors-rainbow (map color->rgb (list "red" "orange" "yellow" "green" "blue" "indigo" "violet"))) ;;; Procedure: ;;; image-render-colors! ;;; Parameters: ;;; image, an image ;;; colors, a list of RGB colors ;;; Purpose: ;;; Render a list of colors in an image. ;;; Produces: ;;; image, the updated image ;;; Preconditions: ;;; colors is nonempty ;;; Postconditions: ;;; Each color in colors has been rendered somewhere on the image. ;;; Philosophy: ;;; Intended mostly as a technique for exploring lists of colors. (define image-render-colors! (lambda (image colors) (let ((width (ceiling (/ (image-width image) (length colors))))) (let kernel ((left 0) (remaining colors)) (cond ((null? remaining) (image-select-nothing! image) (context-update-displays!) image) (else (context-set-fgcolor! (car remaining)) (image-select-rectangle! image REPLACE left 0 (+ 1 width) (image-height image)) (image-fill-selection! image) (kernel (+ left width) (cdr remaining)))))))) ;;; Procedure: ;;; rgb-average ;;; Parameters: ;;; c1, an RGB color ;;; c2, an RGB color ;;; Purpose: ;;; Compute the "average" of two RGB colors. ;;; Produces: ;;; c_ave, an RGB color ;;; Preconditions: ;;; [No additional] ;;; Postconditions: ;;; (rgb-red c_ave) is the average of (rgb-red c1) and (rgb-red c2) ;;; (rgb-green c_ave) is the average of (rgb-green c1) and (rgb-green c2) ;;; (rgb-blue c_ave) is the average of (rgb-blue c1) and (rgb-blue c2) (define rgb-average (lambda (c1 c2) (rgb-new (quotient (+ (rgb-red c1) (rgb-red c2)) 2) (quotient (+ (rgb-green c1) (rgb-green c2)) 2) (quotient (+ (rgb-blue c1) (rgb-blue c2)) 2)))) ;;; Procedures: ;;; left-section ;;; l-s ;;; Parameters: ;;; binproc, a two-parameter procedure ;;; left, a value ;;; Purpose: ;;; Creates a one-parameter procedure by filling in the first parameter ;; of binproc. ;;; Produces: ;;; unproc, a one-parameter procedure ;;; Preconditions: ;;; left is a valid first parameter for binproc. ;;; Postconditions: ;;; (unproc right) = (binproc left right) (define left-section (lambda (binproc arg1) ; Build a new procedure of one argument (lambda (arg2) ; That calls binproc on the appropriate arguments (binproc arg1 arg2)))) (define l-s left-section) ;;; Procedures: ;;; right-section ;;; r-s ;;; Parameters: ;;; binproc, a two-parameter procedure ;;; right, a value ;;; Purpose: ;;; Creates a one-parameter procedure by filling in the second parameter ;; of binproc. ;;; Produces: ;;; unproc, a one-parameter procedure ;;; Preconditions: ;;; left is a valid first parameter for binproc. ;;; Postconditions: ;;; (unproc left) = (binproc left right) (define right-section (lambda (binproc arg2) ; Build a new procedure of one argument (lambda (arg1) ; That calls binproc on the appropriate arguments (binproc arg1 arg2)))) (define r-s right-section) ;;; Procedure: ;;; make-list ;;; Parameters: ;;; n, a non-negative integer ;;; val, a Scheme value ;;; Purpose: ;;; Produce a list that contains n copies of val ;;; Produces: ;;; nvals, a list ;;; Preconditions: ;;; [No additional] ;;; Postconditions: ;;; (length nvals) = n ;;; for each i, 0 <= i < n, ;;; (list-ref nvals i) = val (define make-list (lambda (n val) (let kernel ((i n) (nvals null)) (if (<= i 0) nvals (kernel (- i 1) (cons val nvals)))))) ; +-------+-------------------------------------------------------------------- ; | Added | ; +-------+