In this video, you will program the scanner sprite to stamp the black color where thestage is black, and the white color everywhere else.
The scanner sprite’s selected costume determines which color it stamps the background. Thisstarter project has two 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 stampthe 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 thingor the other--not both! Make sure that the stamp block goes beneath the if/else blockyou just put in the stack For today’s project, the decision is basedon whether or not the sprite is touching the color black. Go to the sensing menu, pullout 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 colorblack, click on the box in the “touching color” block. You should see a little, whitehand. Then, click on the color black in the stage. Now, the “if/else” block will checkeach 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,but right now it stays on the white costume. Add a “switch costume to” block to the“then” part of the “if/else” block, click on the dropdown menu, and select “black.”
Test the code by clicking the green flag.
The sprite starts out using the white costume.
If it touches black, then the costume switches to black. Great!
But, the costume never switches back to white! The sprite knows to switch to the black costumeif 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 whitecostume if it is not touching black, drag another “switch costume to” block insidethe else section. Select “white” from the dropdown menu.
Now the code reads “if touching black, switch to costume black, else - or otherwise - switchto costume white”Now, test your code! If the sprite is touching black, it should stamp black. If the spriteis touching anything else, it should stamp white. It should do this all over the screen.
After you’ve finished this step, share your project by clicking the share button at thetop 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.