Please update your browser
Your browser version is not supported by this site. CS First may not work properly.
In this video,
you’ll smooth out your wave animation so the waves move more gradually.
Right now, when you run your program,
the wave changes effect by 25, waits, then changes back.
To make the waves move more gradually, program them to change in smaller amounts.
You could write a lot of code to do this…
change effect by 5, wait, change effect by 5, wait, and so on,
to make the wave move a little bit at a time.
But, as you saw in the last video,
it’s easier to program the computer to repeat these actions for you.
To do this, drag out a “repeat 10” block.
While the forever loop you used before makes an action repeat for the whole program,
the “repeat 10” block only runs a specified number of times.
Place “change whirl effect” and “wait” blocks inside the “repeat 10” block.
Tinker with the values of the “change whirl effect,” “wait,” and “repeat” blocks
until the water looks like a smooth, natural wave.
As you test your program, if you need to reset the whirl effect to 0,
click the looks menu and the “clear graphic effects” block.
Once your wave looks good to you,
put the “repeat” block back in the forever loop.
Then, do the same for the other “change whirl effect” and “wait” blocks.
Drag out a “repeat 10” block, and place the blocks inside it.
Keep your wave from going too far in one direction
by entering the same values in the “repeat” and “wait” blocks.
Then, use a negative value in the “change whirl effect” block.
Place this code back inside the forever loop, and click the flag to run it.
When the flag is clicked, the forever loop begins to run the code inside.
First, it runs the “repeat” block.
This repeats changing the effect and waiting 10 times.
Then, the next “repeat” block runs.
When that finishes, the whole process starts over again.
Awesome! You should have a smooth looking wave.
In the next video, you’ll add some more sprites
and begin telling a story about what’s happening on this boat!
Now, it’s your turn!
Add a “repeat” block around each pair of “change effect” and “wait” blocks.
Change the values of the blocks to create a smooth wave effect for your program.