In this video, you will program the
scanner sprite to stamp the black color where the stage is
black, and the white color everywhere else.
The scanner sprite's selected costume determines which color
it stamps the background.
This starter project has costumes that are different colors:
White and Black.
In order to make a shadow, the computer needs to decide when
to change the sprite's costume to stamp the correct color.
To make that happen, go to the Control Menu,
find the If Else block,
and place it just above the Stamp Block in the code.
This block creates a decision so that when the code is run,
the computer does one thing or the other, not both.
Make sure that the Stamp Block goes beneath the
If Else Block you just put in the stack.
For today's project, the decision is based on whether or not
the sprite is touching the color black.
Go to the Sensing Menu,
pull out the Touching Color block
and place it inside the If Else block.
Now, the block reads "If touching color"
but the color isn't black.
To make the color black,
click on a box in the Touching Color block.
Then, click on the color black in the stage.
Now, the If Else block will check each pixel
to see if it is black.
Next, tell the sprite what to do when it touches black.
It should stamp the color of its costume.
Add a Switch Costume To block to the Then part of the
If Else block. Click on the drop-down menu and select black.
Test the code by clicking the green flag.
If it touches black, then the costume switches to black.
Great! But, the costume never switches back to white.
The sprite knows how to switch to the black costume if it's
touching black. But it doesn't know what to do otherwise.
That is what the Else part of If Else is for.
To make the sprite change to its white costume
if it is not touching black, drag another
Switch Costume To block inside the Else section.
Select white from the drop-down menu.
Now, the code reads "If touching black,
switch to costume black.
Else, or otherwise, switch to costume white."
Now, test your code.
If the sprite is touching black, it should stamp black.
If the sprite is touching anything else,
it should stamp white.
It should do this all over the screen.
After you finished this step, share your project by clicking
on the Share button at the top of the project editor.
Because this project runs best in Turbo Mode,
add instructions to tell people to turn Turbo Mode on
to use your program.
Now it's your turn. Make the scanner sprite stamp the black
color where the stage is black and the white color
To do this, use an If Else block and include the
Touching Color condition.
Switch costumes according to the If Else condition with the
Change Costume To blocks.
Sign in to save your project and track your progress.