#lang racket
(require gigls/unsafe)
(provide (all-defined-out))

;;; File:
;;;   local-procs-lab.rkt
;;; Authors:
;;;   Janet Davis
;;;   Samuel A. Rebelsky
;;;   Jerod Weinman
;;;   YOUR NAME HERE
;;; Summary:
;;;   Code for the lab entitled "Local Procedures and Recursion"

; +-----------------+-----------------------------------------------------------
; | Color Utilities |
; +-----------------+

;;; Procedure:
;;;   irgb-brightness
;;; Parameters:
;;;   color, an integer-encoded RGB color
;;; Purpose:
;;;   Computes the brightness of color on a 0 (dark) to 100 (light) scale.
;;; Produces:
;;;   brightness, an integer
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   If color1 is likely to be perceived as lighter than color2,
;;;     then (irgb-brightness color1) > (irgb-brightness color2).
;;;   0 <= brightness <= 100
(define irgb-brightness
  (lambda (color)
    (round (* 100 (/ (+ (* 0.30 (irgb-red color))
                        (* 0.59 (irgb-green color))
                        (* 0.11 (irgb-blue color)))
                      255)))))

;;; Procedure:
;;;   irgb-bright?
;;; Parameters:
;;;   color, an integer-encoded RGB color
;;; Purpose:
;;;   Determines whether the color is bright.
;;; Produces:
;;;   bright?, a boolean
;;; Preconditions:
;;;   irgb-brightness is defined.
;;; Postconditions:
;;;   bright? is true iff (irgb-brightness color) >= 67.
(define irgb-bright?
  (lambda (color)
    (<= 67 (irgb-brightness color))))

;;; Procedure:
;;;   irgb-dark?
;;; Parameters:
;;;   color, an RGB color
;;; Purpose:
;;;   Determine whether the color appears dark.
;;; Produces:
;;;   dark?, a Boolean
;;; Preconditions:
;;;   irgb-brightness is defined.
;;; Postconditions:
;;;   If color is relatively dark (brightness not exceeding 33), then dark? is #t.
;;;   Otherwise, dark? is #f.
(define irgb-dark?
  (lambda (color)
     (> 33 (irgb-brightness color))))

;;; Procedure:
;;;   irgb-brighter?
;;; Parameters:
;;;   color1, a color
;;;   color2, a color
;;; Purpose:
;;;   Determine whether color1 is strictly brighter than color 2.
;;; Produces:
;;;   brighter?, a Boolean
;;; Preconditions:
;;;   irgb-brightness is defined.
;;; Postconditions:
;;;   If (irgb-brightness color1) > (irgb-brightness color2)
;;;     then brighter is true (#t)
;;;   Otherwise
;;;     brighter is false (#f)
(define irgb-brighter?
  (lambda (color1 color2)
    (> (irgb-brightness color1) (irgb-brightness color2))))

