Wednesday, 28 November 2012

Week 12: Project 2

In this post, I am going to talk about the things I have learnt and problems that I encountered in the Project 2.

1. min and max

This function is about finding the smaller or bigger number from the list.
For example,
(min 10 5)
>5
(max 10 100)
>100
I was not so sure about this function before I looked it up in the textbook.



 2. interpolate-color

The function "strict-interpolate" was not hard to understand, it is just about calculating the number with "interpolate" and then finding the minimum or maximum number.
I got stuck on putting two functions together on "interpolate-color".
This time it's not about using "map" or "map-image", I tried things like


(define (interpolate-color f c1 c2) (make-color
                                 (color-red (strict-interpolate f c1 c2))
                                 (color-green (strict-interpolate f c1 c2))
                                 (color-blue (strict-interpolate f c1 c2))
                                 255))
(define (interpolate-color f c1 c2) (make-color
                                 (color-red (strict-interpolate f (color-red c1) (color-red c2)))
                                 (color-green (strict-interpolate f (color-green c1) (color-green c2)))
                                 (color-blue (strict-interpolate f (color-blue c1) (color-blue c2)))
                                 255)) 

However, it is actually like this

(define (interpolate-color f c1 c2)
  (make-color (strict-interpolate f (color-red c1)(color-red c2))
              (strict-interpolate f (color-green c1)(color-green c2))
              (strict-interpolate f (color-blue c1)(color-blue c2))
              (strict-interpolate f (color-alpha c1)(color-alpha c2))))


2.  arrow-event

By studying these "check-expects",

(check-expect (arrow-event 3 "left") 2)
(check-expect (arrow-event 3 "right") 4)
(check-expect (arrow-event 3 "up") 3)

I fixed the function by referring the recursion exercises, at last I got it working.

(define (arrow-event n k)
  (cond
    [(equal? k "left")(- n 1)]
    [(equal? k "right")(+ n 1)]
    [else n]))


In conclusion, this project is seemed to be shorter than project 1; however, this is not really a piece of cake for me. Without doubt, this project as well involves lots of thinking and understanding of the usage of codes.


No comments:

Post a Comment