Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more.

3. Animate a Wave

Transcript

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 the stage.

Sprite is another word for a character or an object.

In Scratch, you will program sprites to do different things.

In this menu, you'll 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 effect's, click the clear graphics effect block to reset the water sprite to it's original appearance.

Select the whirl effect and click to run the block.

That is starting to look like a wave.

To select this block for your program, click on it and drag it into the script's 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 and 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, and click to run it.

Nothing happened.

This is because the computer can run code much faster than you can click between blocks.

The computer doesn't wait between running different parts of the code, so you can't see the effects change.

To fix this, tell the computer to wait before running each code block.

Click control and drag a wait block between the change whirl effect by blocks.

Click to run it.

The computer runs the first effect block, waits one second, then runs the next.

This is a great start, but this code only makes one wave.

You can copy this code a bunch of times to create a really long program, or you can program the computer to repeat 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 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.

Great, to run this code, you have to click the block stack.

This is okay 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 an ocean.

Now it's your turn.

Add a change whirl effect block to create the wave effect.

Add a change whirl effect by negative 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, and add a when flag clicked block to run this code stack when the flag is clicked.

arrow_backward Back
Next arrow_forward
Instructions
  1. Add a "change whirl effect" block to create the wave effect.
  2. Add a "change whirl effect by -25" to reverse the wave effect.
  3. Place a wait block after each "change effect by" block.
  4. Make the wave keep going with a "forever" block.
  5. Add a "when flag clicked" block to run this code stack when the flag is clicked.