This is just a short section to introduce a type of puzzle, which is built on
the sort of image manipulation code we've been doing. So the idea is, there's a picture of some
mystery object. And the red, green and blue values in the image have just been
messed up in some way. And so, what you need to do is write code to fix the
red, green, and blue values, and so reveal the original image, and, and see what it is.
So, here is an example I'm gonna do here. This is the so called "Gold Puzzle".
And, the idea, so there's, there's, some object is shown here. And what's happened with this
is that, first of all, the green and blue values in the image have been just
set with random values between zero and 255. And actually, if you look at it,
so it gives a kind of a, a snowy appearance. And it, you can kinda see, there's,
so there's some pixels where the green is very high, some pixels where the blue is very high,
they just look blue or green; and then there's these sort of turquoise pixels scattered through;
so those are cases where, both the blue and the green are high. So that's one,
one level of mess-up in this image. The other thing that's happened
is that the image that we wanna recover, it's in the
red values. In fact, it's exclusively in the red values. The green and blue are just, sort of, garbage.
But the values have been divided by ten, so they're very dark. So, kind of what we're seeing here
in the obscure version, is, there's, there's a dark red image
behind there. And it's been covered with this, sort of bright random
green blue snow, so we can't see it. So what we want to do is, write code to fix it.
So let me start off here. So as usual, for these, I'm going to start off
with just a blank text area to just write the code. And then down here there's a solution,
"Show solution" button. So if you wanted to visit this page and try it yourself, you can, you can get the code that way.
Alright, so the first thing I want to do, so here's, here's what it looks like if I just run it right here:
the loop is empty; so if I run it, we just, we just get the, the puzzle image raw.
Alright, so the first thing I'm going to do is I'll say
pixel.setGreen(0)
I'm going to punch out the green values. I'm just going to get rid of them
and we'll see what we get. Hmm, alright, So now, well, it's better. Now, we just
have this blue snow. We've at least gotten rid of the green snow. So I'll get rid of the blue snow as well.
So I'll say, pixel.SetBlue(0), we'll try that.
Alright, hmm, So, I, I've got rid of the snow. But now the problem is that the
image, which is in the red values. It's just so dark, we can't see it. So it is,
it's technically there, but it's invisible. So what I need to is scale it back up,
right? It's down there, I just need to make it brighter. So I'll say pixel.setRed of
pixel-dot-getRed" Looks a little bit like the five, ten, twenty
puzzles here. So I'm gonna, in this case, the instructions say that it was scaled down
by a factor of ten. So I'll scale the red back up by a factor of ten.
Huh, there we go. So that, that is the solution image. So,
this is a picture of the Golden Gate Bridge, as seen from the San Francisco side. Now,
it's a little, obviously, it doesn't look quite right. What's happened, is that, because
the data is exclusively in the red, even when we recover it, it just looks red. I mean, what's,
what's happened, actually. Is this is an essentially a black and white image
and normally those are shown on a, on a sort of black to white spectrum. In this case,
the image is being shown on a black to red spectrum. So it is the right image but it just,
it has this red cast. For this sections we're gonna say that's good enough: you know,
you can see what it's supposed to be. In a later section I'll show how to,
how to fix that. And get it to look like a, a proper black and white image.