Just submitted project #2! This time around, I was able to complete it without much trouble. But, of course there was one or two questions that stumped me for a while longer than I'd like. One of them was 'interpolate-color'.
So I first attempted this problem by examining the check-expects:
(check-expect (interpolate-color 2/3 (make-color 0 0 0 255) (make-color 6 9 12 255))
(make-color 4 6 8 255)
Then I compared it with the definition that was given:
(define (interpolate-color f c1 c2) c1)
Comparing these two, I know what f, c1, and c2 corresponded to. But I was a bit confused about the last c1 in the given definition.
Reading the instructions I also realized I should use strict-interpolate in the definition as well.
Combining the knowledge that I got, I started messing around with the definition. Going back to what I said previously, the last c1 seemed to be a bit off. So I realized that what needed fixing was not the beginning of the definition but the last part where 'c1' was.
To better understand what I had to do, I made sure I knew what 'interpolate-color' was meant to do, which was applying the 'strictly-interpolate' function but the changes would affect a colour. After realizing the definition's purpose, I knew I had to use 'make-color'. Applying the knowledge on 'make-color' and using strict-interpolate, I came up with this definition:
(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))))
After running it:
All tests passed!
Hopefully, my exam will go as well!
Bye CSC104!
Bye-Bye blog, maybe I'll post something again once and a while (:
No comments:
Post a Comment