arrow_back For the Camera
In this add-on, you will program a photographer to take pictures of a model that comes on stage. First, add a photographer. You can add a new sprite from the Sprite library. You can also download a photographer sprite from the "images" link or copy it to your backpack from the "Additional Images Project" link on the add-on page. To learn how to add images to your Scratch project, watch the "Upload Images" video by clicking on its link on the add-on page. Drag out a “broadcast” block.” Broadcast is an event that triggers certain code to run, which is why it's found under the events menu. Click on the black triangle to display a dropdown menu, and click “new message.” This example names the message “flash” because it will trigger code to create a camera flash on screen. Next, add code for the stage to flash. Click the stage. For every broadcast block, there needs to be a “when I receive” event block to run the broadcasted code. From the events menu, add “when I receive” block, and match the message, flash. Create a flash effect using the “change effect” block. Select “brightness” from the dropdown menu on this block. Now, when the program broadcasts the message “flash,” the backdrop gets brighter.
This should look like a flash, so program the backdrop to go back to its normal appearance using a "clear graphic effects" block. Click this stack to test.
Nothing happens. There needs to be a delay between the flash and the clearing of graphic effects. To fix this, drag out a “wait” block. Change the value to something smaller than 1 second so the flash can be quick! This example uses 0.08 seconds. Now test this!
Great. Next, program the photographer to randomly take pictures.
Click back on the photographer sprite, add a “forever” loop around the “broadcast” block, then add a “wait” block. Great. The photographer will take a picture every second. To make the time between shots random, add a “pick random” block from the operators menu inside the “wait” block. Tinker with the values inside the block, so the program won’t wait too long to take a picture. This example uses 0.5 and 2 as the values in the “pick random” block. Add a “when flag clicked” block to run this code when the program starts. Cool! Finally, add a sound when the camera flashes.
Click the sounds tab, and choose a sound you like from the sound menu. This example uses “hand clap.” Next, click to the scripts tab, then Sound, and add a “play sound” block after the “broadcast” block. Test this. It works! Great.
Now it’s your turn! Add a new photographer sprite, then create a broadcast effect using “when I receive”, “change brightness effect,” "clear graphic effects," and “wait” blocks. Make your photographer randomly take pictures using the “broadcast” “play sound” “wait” and “pick random” blocks inside a “forever” loop. Add a “when flag clicked” event to start this code stack.