Functional Problem Solving (CSC 151 2014F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Readings]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2014S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
What is going to be on the quiz tomorrow?
image-variant
and image-transform!
.compose
and o
.map
and the other subjects we did yesterday.What do you see as the standard color transformations and what do we need to do with them?
Could you give us some sample quiz questions?
This picture of Casey (image name is casey
) has not enough red and
is a bit too dark. Write code to make an improved version of that
picture.
(define temp (image-variant casey irgb-redder))
(image-variant temp irgb-lighter)
(image-variant (image-variant casey irgb-redder) irgb-lighter)
(image-variant casey (o irgb-lighter irgb-redder))
This picture of Casey (image name is casey
) has not enough red and
is a bit too dark. Write code to make the picture better.
(image-transform! casey irgb-redder)
(image-transform! casey irgb-lighter)
(image-transform! (image-transform! casey irgb-redder) irgb-lighter)
(image-transform! casey (o irgb-lighter irgb-redder))
This picture of Casey (image name is casey
) has too much red and
is a bit too dark. Write code to make the picture better.
(image-transform! casey (o irgb-greener irgb-bluer irgb-lighter))
(image-transform! casey (o irgb-greener irgb-bluer))
Are there colors for which (irgb-lighter (irgb-darker color))
is
not the same as (irgb-darker (irgb-lighter color))
?
(irgb-darker color)
is just
black, making them lighter will then make them really dark greyAre there colors for which (irgb-lighter (irgb-redder color))
is different than (irgb-redder (irgb-lighter color))
?
What qualifies a color as "blue" rather than something else?
When might we use lambda?
image-variant
or image-transform!
and you
need to generate a new transformation on the fly.Quiz question: Write an instruction to transform the image of casey so that the green component is set to 0 and the red component is (approximate) halved.
(define irgb-damage
(lambda (color)
(irgb (round (/ (rgb-red color) 2))
0
(irgb-blue color))))
(image-transform! casey irgb-damage)
(image-transform! casey
(lambda (color) (irgb (round (/ (irgb-red color) 2))
0
(irgb-blue color))))
Over the longer term, you'll use lambdas almost any time you need a "one time use" function.
Example: Write a function, (redder-by! image amount)
, which increases the
red component of the given image by the specified amount. For example,
(redder-by! casey 20)
, the red component of each pixel should increase
by 20 (up to 255). Similarly, `(redder-by! casey -5)1, the red component
of each pixel should decrease by 5 (increase by -5)
(define redder-by!
(lambda (image amount)
(image-transform! image
(lambda (color) (irgb (+ amount (rgb-red color))
(irgb-green color)
(irgb-blue color))))))
vs.
(define redder-by!
(lambda (image amount)
(image-transform! image somewhat-redder)))
(define somewhat-redder
(lambda (color)
(irgb (+ amount (irgb-red color))
(irgb-green color)
(irgb-blue color))))
The problem in the second is that somewhat-redder
doesn't have access
to amount
.