Map
perOther XML tasks for Mary: remove all opacity stuff. --MF, 8/25/21
In the future, we could have a histogram/pictograph showing how much red, green, and blue is in the image, building on 1.3. Thoughts? --MF, 8/26/21
Also/alternatively, we could do the frequency analysis stuff from the Jens's Snap! 5 Data Science video. --MF, 8/29/21
This page is super long!! Cut it up into multiple pages. --MF, 1/11/23
You can use code to access information about one color of a pixel.
item of
...Now write a function that use item of
to select just the green color value from the 85th pixel in the pixels of my costume
table.
Imagine you had a list of RGB color values, such as . Consider: How could you use
item of
to select the green value? Then, recall that item (85) of (pixels of my costume)
reports a list of RGB color values for the 85th pixel of the current costume.
The block makes this job easier. Instead of having two
item of
blocks (which can be confusing), this block takes a color name and a pixel as input and it applies item of
(with the correct input number) to the input pixel.
Hiding the details of how color from pixel
selects the correct RGB value from a pixel (so you don't have to see the extra item of
block) is a form of abstraction.
draw pixel
block as a one-pixel segue into mapping channel edits over an image. --MF, 8/27/21Map
ping over a ListYou can use to apply any block that works on one list item to every item in a list.
map
to apply color from pixel
to every pixel in the pixels of costume
list.map
expression to the output of pixels of costume
.color from pixel
block, and compare to pixels of costume
again.map
expression do?
map
expression does.
Since reports a single color value from the input pixel (in this case, the red value), the expression
reports a single color value from each pixel in the
pixels of costume
list (in this case, the red value of each pixel).
Click for an example of what the map
expression reports.
For example, with "red" as the input to color from pixel
, the map
expression reports a list of only the red values of all the costume's pixels:
pixels of costume
map
ping color (red) from pixel
over pixels of costume
Map
is a higher-order function. That just means that it's a function that takes a function (in this case, color from pixel
) as input.
This map
expression
takes two inputs:
color from pixel
:
You can tell the difference between the second input slot to , which takes the output of a function (like most inputs do), and the first input slot, which takes a whole function itself (not its output), because the first input slot has a gray ring around it. The gray ring tells you that the
map
function is expecting a function (not the output of a function) as input.
Map
takes a function as input so it can apply that function to each item in the list. The empty input slot in the function (in this case, the pixel) is where each item from the list (in this case, the list of pixels) goes every time the function is applied.
map
examples to predict and then try out in Snap! before going on... --MF, 10/15/21 map
expression report?use costume
dropdown menu.Click for a description of what Mystery Filter #1 does.
Mystery Filter #1 creates a new costume which contains only the red pixels from the original costume by setting the green and blue to zero. Mouse over the result to verify that there are no pixels with any green or blue in them.
RGB pixel
block out of the paint color
block and into the scale pixel
block, and click the new scale pixel
expression.scale pixel
block change the values of the input pixel?
scale pixel
expression into the paint color
block and click it? Try it.map
expression will to the pixels from the costume?Click for a description of what Mystery Filter #2 does.
Mystery Filter #2 brightens the whole image by increasing the red, green, and blue values each to 200% (twice) their original value. This brings them closer to white: 255, 255, 255 (unless they started at 0).
scale up
block won't change black pixels. Why not?map
, and used map
to explore several filters that transformed each pixel in the image.