DarkerLighter

From MHCGraphics

Jump to: navigation, search
; Mead example file demonstrating some list functions
;
; Jim Teresco
; Computer Science 110
; Mount Holyoke College
;
; $Id: DarkerLighter.scm 569 2008-03-24 02:09:18Z terescoj $
;
(require (lib "Defs.ss" "Mead"))

; define some convenient names for list manipulation functions
(define (first l) (car l))
(define (rest l) (cdr l))
(define (second l) (cadr l))
(define (third l) (caddr l))

; RGB colors are lists.  The following function
; generates a darker RGB color.  We take each component
; out of the given color with the first, second, third
; functions, divide each result by 2, and construct a new
; list out of the three results.  The returned value is 
; also a valid RGB color.
(define (darker c)
  (list
   (/ (first c) 2.0)
   (/ (second c) 2.0)
   (/ (third c) 2.0)))

; Lighter could be defined along those same lines, as follows:
(define (lighter c)
  (list
   (- 1 (* 0.5 (- 1 (first c))))
   (- 1 (* 0.5 (- 1 (second c))))
   (- 1 (* 0.5 (- 1 (third c))))))

; We play with our darker and lighter functions
(object lighterRedPlaster Material
        (type 'plaster)
        (color (lighter red)))
(object darkerRedPlaster Material
        (type 'plaster)
        (color (darker red)))
(object lighterLighterRedPlaster Material
        (type 'plaster)
        (color (lighter (lighter red))))
(object darkerDarkerRedPlaster Material
        (type 'plaster)
        (color (darker (darker red))))


(tell scene
      (add sphere redPlaster)
      (add sphere lighterRedPlaster
           (translate 100 0 0)
           )
      (add sphere darkerRedPlaster
           (translate -100 0 0)
           )
      (add sphere lighterLighterRedPlaster
           (translate 200 0 0)
           )
      (add sphere darkerDarkerRedPlaster
           (translate -200 0 0)
           )
      )

(tell image
      (background white))

(tell camera
      (angle 80)
      (shoot))
Personal tools