In this video, you’ll animate the water to create a wave effect.
Watch this video to learn how, then switch over to Scratch and try it on your own.
This is the Scratch project editor.
It contains two sprites on a stage.
“Sprite” is another word for a character or an object.
In Scratch, you will program sprites to do different things.
In the middle of the screen, you’ll see a scripts menu.
In this menu, you will find the instruction blocks you’ll use to create programs.
To start, click the water sprite.
The code blocks you select will run for this sprite.
Next, click the purple looks menu.
Scratch blocks are color-coded, so purple blocks are in the purple looks menu.
Looks blocks change a sprite’s appearance.
To create a wave, use the "change effect by" block.
To run the block, just click it!
The water should change color.
Some blocks, like this “effects” block, have a value that you can change.
Click the dropdown to select a different effect, and click the block to run it.
After trying a few effects, click the “clear graphic effects” block to reset the water sprite to its original appearance.
Select the whirl effect, and click to run the block.
That’s starting to look like a wave!
To select this block for your program, click on it, and drag it into the scripts editor.
Each time you run this block, the whirl effect gets more intense.
To reverse the whirl effect, change the value in the whirl block to a negative number.
Click and run this a few times.
You should see the whirl effect slowly reversing.
These are the beginnings of a computer program!
Rather than clicking this block a bunch of times, changing the value to something negative, then clicking it a bunch more times, you can program the computer to do these actions for you!
Drag out another “change effect by” block.
For this to look like a real wave, it should go up, then back down.
To make the wave go up, use the “change whirl effect by 25” block.
The “change by negative 25” block will make it go back down.
To run blocks in order, snap them together.
Click to run it.
This is because the computer can run code much faster than you can click between blocks.
The computer doesn’t wait between running the different parts of the code, so you can’t see the effects change.
To fix this, tell the computer to wait between running each code block.
Click control, and drag a “wait” block between the two “change whirl effect by” blocks.
Click to run it.
The computer runs the first effect block, waits 1 second, then runs the next.
This is a great start, but this code only makes one wave.
You could copy this code a bunch of times to create a really long program...
Or, you could program the computer to repeat the code for you!
From the control menu, drag out a “forever” block, and place it around the code you already created. Click to run it.
Uh oh, something unexpected is happening here.
When this code repeats, the “change whirl effect by -25” block runs, then the next “change whirl effect” block runs right away.
To fix this, add a “wait” block after the second change whirl effect block.
Click to run it!
To run this code, you have to click the block stack.
This is OK for testing, but when someone else runs your program they should be able to click a play button.
In Scratch, the play button is the flag at the top of the stage.
Using the flag to start the program will also help later, when you want to run different block stacks at the same time.
To run this code when the flag is clicked, select events, and add a “when flag clicked” block to the top of your code.
Click the flag to try it out! Great!
In the next video, you’ll program the wave effect to be smoother, so it looks like the rocking of the ocean.
Now, it’s your turn: Add a “change whirl effect” block to create the wave effect.
Add a “change whirl effect by -25” to reverse the wave effect.
Place a wait block after each “change effect by” block.
Make the wave keep going with a “forever” block.
Add a “when flag clicked” block to run this code stack when the flag is clicked.
- Add a "change whirl effect" block to create the wave effect.
- Add a "change whirl effect by -25" to reverse the wave effect.
- Place a wait block after each "change effect by" block.
- Make the wave keep going with a "forever" block.
- Add a "when flag clicked" block to run this code stack when the flag is clicked.