There is something not quite right about the pixel X/Y calculation, and I posted in channel about that. Students haven't noticed so far but someone will point it out soon, I'm sure. - Pamela 9/10/21
The use costume
block does not appear to be in this project. Also, the image of it below needs to be resized. --MF, 4/11/22
Also, we need to resize all of the images in the lab going forward (and perhaps those coming from other labs as well.) --MF, 4/11/22
Consider splitting up this page (and others in this lab). Also try to make the lab less didactic. --MF, 7/24/23
As you've discovered, the images on a screen are made up of pixels (tiny squares of color). Using a few powerful blocks, you can transform the pixels in a picture to make fun filters.
use costume
block switches the sprite costume (the image shown on the stage). Choose a costume from the dropdown menu, and click the block. Try a few different costumes until you find one you like.The three RGB values show the amount of red, green, and blue in the pixel under the mouse pointer.
The XY values are the horizontal (x) and vertical (y) positions of the mouse pointer.
Pixel Number identifies the number of the pixel under the mouse pointer. (The pixels are numbered starting from the top left corner, going across the first row of pixels, and then moving down to each of the following rows.)
A sprite is an object that has scripts and a costume and can even move around on the stage.
This project has two sprites: the Image sprite (in the center of the stage), and the PixelGrid sprite (in the top left). The Image sprite has the code you'll be playing with, and the PixelGrid sprite has the code that makes the grid of pixels.
A costume is picture that can be "worn" by a sprite.
use costume
block switches the Image sprite's current costume to the costume selected in the dropdown menu. These are optional extra steps for anyone who has access to a webcam or has a own photo of their own.
If you have a webcam, click the camera icon (). The browser may ask you for permission and then give you a way to snap a photo. Say cheese! Alternatively, if you have a photo on your computer, drag it into the "Costumes" area.
use costume
block, and inspect its pixels. Perhaps you'll discover your eye color isn't exactly as "blue", "green", "brown", or "gray" in this picture as you thought it was. 😉Computers store pixels as a list of RGB values (as you've seen) and store images as a table of pixels (a list of lists).
pixels of my costume
block. It reports a (very long) table of pixel values. A list is an ordered sequence of items, and a table is an ordered sequence of lists. So, a table is a list of lists. Each row in a table is another smaller list.
The output of the pixels of my costume
block is a table with three columns. Each row is one pixel from the image (each with red, green, and blue values), so the three columns in the table are the amount of red, green, and blue in each pixel of the image.
Click the pixels of my costume
block, and then right-click the table that appears and select "list view...". You will see the exact same data displayed as a list of lists. (You can right-click the over-arching list and select "table view..." to see the data as a table again.)
Because a table is a list, you can use the block to select one row of RGB values from the table (that is, one pixel from the list). You have seen item of
select a random item from a list:
Since each item in the output of the pixels of my costume
block is one pixel, you can use item of
to retrieve the list of color values for one pixel at at time.
item (1) of (pixels of my costume)
is a list of three values: the amount of red, green, and blue in the first pixel of the costume.item (1) of (pixels of my costume)
(that is, change the "1") to the pixel number you wrote down, and run that code again. The output should match the RGB value you wrote down.
item of
block do?pixels of my costume
that becomes the input to item of
?item of (pixels of my costume)
reports what it does.item of
to select one item from a list.