In this video, you will learn how to use the “pick random” block to make your clones’movement unexpected and interesting. Click on the operators menu, and drag the"pick random" block into the value area of the "wait" block.
The “pick random” block chooses a random number between these two values each timeit runs. With the “pick random” block inside the “wait” block, the computermight wait 1 second, then 5 seconds... it will choose a random wait period every time.
With the "pick random" block added, the flying clones do not fly onto the screen over andover again at the same pace. Remember, you can always experiment with these values.
Now that you’ve randomized how long the computer waits between creating clones, randomizewhere the clones start and glide.
Start the sprite at a random height by adding another "pick random" block to the "go to"block's y value. Set the values to negative 180 and 180 to represent the top and bottomof the screen. To make the sprite glide to random height,add another "pick random" block with the same values to the “glide” block.
Test this out. The clones should now start and end at random heights.
You can further experiment with random values by making the clones glide at different speeds.
Add a "pick random" block to the seconds value in the “glide” block.
The size of the clone can also be randomly generated. Click on the "looks" menu, dragout a "set size to 100%" block, and add it to the top of the "when I start as clone"stack. 100% is the original size. A value smallerthan 100%, will make the clone smaller. To randomly select a value for the “setsize to” block, add a "pick random" block. Choose the smallest and largest percent valuesyou want the clones to be. Great!
Test your code. Now, the window is filled with many clonesof the flying sprite, and each clone has its own randomly selected size, speed, and behavior.
By cloning these sprites, you've created many objects, each with its own attributes likesize, and its own behavior, like gliding speed. Lastly, place the storefront sprite in frontof your other sprites. To do this, click on the storefront, and the looks menu. Drag outa "go to front" block, and place a “when flag clicked” event above it. Click theflag. Since the storefront window is transparent, you'll see the flying sprites.
Scratch is more than just a programming language. It’s a community of like-minded users whoshare projects, inspiration, and encouragement. Join in by filling out your profile page withwhat you like to do and what you’re working on in Scratch. Never share personal information,like your home address or last name, on Scratch or any internet site.
Now, it's your turn: Add "pick random" blocks to the y values ofyour “go-to” and “glide” blocks. Add a "set size to" block with a "pick random"block to randomly change the size of the sprite Then, add a "go to front" block and a “whenflag clicked” event to the storefront sprite to make your clones show through the storewindow.