#lang racket
(require gigls/unsafe)
(require rackunit)
(require rackunit/text-ui)

;;; File:
;;;   exam.rkt
;;; Authors:
;;;   The student currently referred to as 000000
;;;   Professor 1
;;;   Professor 2
;;; Contents:
;;;   Code and solutions for Exam 2 2016S
;;; Citations:
;;;

;; +---------+--------------------------------------------------------
;; | Grading |
;; +---------+

;; This section is for the grader's use.

;; Problem 1:   
;; Problem 2:   
;; Problem 3:   
;; Problem 4:   
;; Problem 5:   
;; Problem 6:   
;; Problem 7:   
;;           ----
;;     Total:   

;;    Scaled:   
;;    Errors:   
;;     Times:   
;;          :   
;;          :   
;;          :   
;;           ----
;;     Total:


;; +-----------+------------------------------------------------------
;; | Problem 1 |
;; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   color-names-much-bluer
;;; Parameters:
;;;   names, a list of strings
;;; Purpose:
;;;   Find the names of bluer versions of the colors in names
;;; Produces:
;;;   bluer-names, a list of strings
;;; Preconditions:
;;;   For all values, name, in names, (color-name? name) holds.
;;; Postconditions:
;;;   For all values, name in bluer-names, (color-name? name) holds.
;;;   (length bluer-names) = (length names)
;;;   For all i, 0 <= i < (length names)
;;;     Given that name-i is the ith element of names, and bluer-i is 
;;;     the ith element of bluer-names, 
;;;       bluer-i = 
;;;         (irgb->color-name (irgb-bluer (irgb-bluer (color->irgb name-i))))
(define color-names-much-bluer
  (lambda (names)
    names)) ; STUB

; Examples/Tests:


;; +-----------+------------------------------------------------------
;; | Problem 2 |
;; +-----------+

; Time Spent: 

; Citations:

; Supplied procedure:

; (irgb-distance c1 c2)
;   A metric for the "distance" between two integer-encoded RGB colors.
(define irgb-distance
  (lambda (c1 c2)
    (inexact->exact
     (round
      (sqrt
       (+ (square (- (irgb-red c1) (irgb-red c2)))
          (square (- (irgb-green c1) (irgb-green c2)))
          (square (- (irgb-blue c1) (irgb-blue c2)))))))))

; Solution:

;;; Procedure:
;;;   
;;; Parameters:
;;;
;;; Purpose:
;;;
;;; Produces:
;;;
(define irgb-speckle-4 
  (lambda (original option1 option2 option3 option4)
    option1)) ; STUB

; Examples/Tests:


;; +-----------+------------------------------------------------------
;; | Problem 3 |
;; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   
;;; Parameters:
;;;   name, a type
;;;   name, a type
;;;   name, a type
;;; Purpose:
;;;
;;; Produces:
;;;   name, a type
;;; Preconditions:
;;;
;;; Postconditions:
;;;
(define alternate-scale
  (lambda (hpercent vpercent drawing)
    drawing)) ; STUB

; Examples/Tests:


;; +-----------+------------------------------------------------------
;; | Problem 4 |
;; +-----------+

; Time Spent: 

; Citations:

; Provided code:

; (check-scaling message original scaled hscale vscale)
;   Determine if scaled is original, scaled by the appropriate
;   scale factors, and with the same top and left.
(define check-scaling
  (lambda (message original scaled hscale vscale)
    (test-case
     message
     (check-= (drawing-left scaled) (drawing-left original) 
              .001 
              "left")
     (check-= (drawing-top scaled) (drawing-top original) 
              .001
              "top")
     (check-= (drawing-width scaled) (* hscale  (drawing-width original)) 
              .001
              "width")
     (check-= (drawing-height scaled) (* vscale  (drawing-height original)) 
              .001
              "height")
     (check-equal? (drawing-color scaled) (drawing-color original)
                   "color")
     (check-equal? (drawing-type scaled) (drawing-type original)
                   "type"))))

; Solution:

(define alternate-scale-tests
  (test-suite
   "Tests of alternate-scale"
   (test-case
    "Unit square"
    (check-scaling "unit-square-same" 
                   drawing-unit-square
                   (alternate-scale 1 1 drawing-unit-square)
                   1 1)
    (check-scaling "unit-square-larger" 
                   drawing-unit-square
                   (alternate-scale 20 10 drawing-unit-square)
                   20 10))))


; Examples/Tests:

; > (run-tests alternate-scale-tests

;; +-----------+------------------------------------------------------
;; | Problem 5 |
;; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;   radial-green-blend
;;; Parameters:
;;;   width, a positive integer
;;;   height, a positive integer
;;;   radius, a positive integer
;;;   center-col, a non-negative integer
;;;   center-row, a non-negative integer
;;;   initial, an integer
;;;   final, an integer
;;; Purpose:
;;;   Create a width-by-height image that contains a green radial blend
;;;   centered at (center-col, center-row).
;;; Produces:
;;;   blend, an image
;;; Preconditions:
;;;   0 <= center-col < width
;;;   0 <= center-row < height
;;;   0 <= initial <= 255
;;;   0 <= final <= 255
;;; Postconditions:
;;;   (image-width blend) = width
;;;   (image-height blend) = height
;;;   For any position (i,j) in the image
;;;     (irgb-red (image-get-pixel blend i j)) = 0
;;;     (irgb-blue (image-get-pixel blend i j)) = 0
;;;   (irgb-green (image-get-pixel blend center-col center-row)) = initial
;;;   For any position (i,j) that is radius away from (center-col,center-row),
;;;     (irgb-green (image-get-pixel blend i j)) = final
;;;   For any other position less than radius away from the center, the 
;;;     green component is appropriately scaled between initial and final.
(define radial-green-blend
  (lambda (width height radius center-col center-row initial final)
    (image-compute (lambda (col row) 
                     (irgb 0 255 0))
                   width height))) ; STUB

; Examples/Tests:


;; +-----------+------------------------------------------------------
;; | Problem 6 |
;; +-----------+

; Time Spent: 

; Citations:

; Provided code:

; (alohraw image n)
;   Make an n-by-n copy of image, at the same width and height of image.
(define alohraw
  (lambda (source n)
    (let ([target (image-new (image-width source) (image-height source))])
      (map (section drella! source target n <>)
           (iota n))
      target)))

; Solution:

;;; Procedure:
;;;   drella!
;;; Parameters:
;;;   source, an image
;;;   target, an image
;;;   n, a positive integer
;;;   row, a non-negative integer
;;; Purpose:
;;;   Make a row of the specified number of n scaled copies of
;;;   the source image in the target image.
;;; Produces:
;;;   [Nothing; called for the side effect]
;;; Preconditions:
;;;   (image-width target) = (image-width source)
;;;   (image-height target) = (image-height target)
;;;   (image-width source) is an integer multiple of n.  That is,
;;;     (integer? (/ (image-width source) n))
;;;   (image-height source) is an integer multiple of n.  That is,
;;;     (integer? (/ (image-height source) n))
;;;   0 <= row < n 
;;; Postconditions:
;;;   target now contains n scaled copies of source.
;;;   Each copy is 1/n the width and 1/n the height of source.
;;;   The copies are side-by-side, with the first copy's left edge
;;;     at the left edge of target and the last copy's right edge
;;;     at the right edge of target.
;;;   The top of each copy is row/n from the top of copy.
(define drella!
  (lambda (source target n row)
    (void))) ; STUB

; Examples/Tests:


;; +-----------+------------------------------------------------------
;; | Problem 7 |
;; +-----------+

; Time Spent: 

; Citations:

; Solution:

;;; Procedure:
;;;
;;; Parameters:
;;;   name, a value
;;;   name, a value
;;;   name, a value
;;;   name, a value
;;;   name, a value
;;;   name, a value
;;; Purpose:
;;;
;;; Produces:
;;;   name, a value
;;; Preconditions:
;;;
;;; Postconditions:
(define jpt (lambda (color image y w h x)
(image-select-ellipse! color REPLACE y w (- h y) (- x w)) (if (=
image 1) (image-select-rectangle! color ADD y w (* 1/2 (- h y)) (*
1/2 (- x w))) (if (= 2 image) (image-select-rectangle! color ADD y (+
w (* 1/2 (- x w))) (* 1/2 (- h y)) (* 1/2 (- x w))) (if (= 3 image)
(image-select-rectangle! color ADD (+ y (* 1/2 (- h y))) w (* 1/2 (- h
y)) (* 1/2 (- x w))) (if (= image 4) (image-select-rectangle! color ADD
(+ y (* 1/2 (- h y))) (+ w (* 1/2 (- x w))) (* 1/2 (- h y)) (* 1/2 (-
x w))) (error "I don't like the value" image))))) (image-fill! color)
(image-select-nothing! color) color))

; Examples/Tests:

