Tip:
Highlight text to annotate it
X
startup Doctor Racket
make sure you're using the racket language itself
and also
under the language menu check that you're indeed using the language
specified at source, so there's no surprises.
You'll need some image tools, so require
2htdp/image, standard image library and then
put my dsheap/color-utils
from planet.
These may take awhile to load at first,
but, subsequently, not so long. Click F5,
and then Control-D, and you're working in the interactions pane.
Now you'll need an elephant to work with... there's one!
cut the elephant so that you can paste it later on in to your program.
We'll paste it into this definition, so that jumbo becomes a shortcut for our
elephant. Jumbo is a riot of colors.
We'd like to make a list of those colors,
by turning
an image into a color-list.
It's a pretty lengthy list though, and not practical to work with all at once,
so instead of all fifty thousand colors, let's just look at the first five.
They have a predictable pattern:
first the red intensity, then the green, then the blue, and then the opacity, and
these are all numbers from 0 through 255.
Let's look at just one color. So the seventeenth color
in jumbo looks like that:
intensity of 174 for red.
We can pull out just the red
part of that, with
color-red,
or we can pull out just the blue intensity with color-blue
We can base a new color
on an existing color by saying:
I'm going to specify the red and then use the existing color for the rest of it. So
the red will be 25, everything else will be the same as color 17.
Or i can specified the blue part and make everything else the same
as the previous color.
so now the blue part will be 26, and everything looks will be as in the
17th color.
Here's how we go about changing all the colors in an image at once. We bind the
name old-col to each color in turn and then I can do something like:
create a new green,
which will be
the average of 255 or the greenest
possible
and the existing green in old-col.
And then the template will be the old color in jumbo itself. So I'm making it all a
bit greener...