This document provides instructions for creating sprite movement and animation projects in Scratch. It begins with lessons on making a sprite move around the screen using go to and move blocks. It then covers topics like turning, repeating movements with loops, and making sprites move smoothly. Later lessons discuss sending and receiving messages between sprites to choreograph their movements, and using forever loops to repeat actions indefinitely. The document concludes by explaining the differences between bitmap and vector drawing modes in Scratch and how this impacts selecting and rotating objects.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
101 views
An Introduction To Programming With Scratch
This document provides instructions for creating sprite movement and animation projects in Scratch. It begins with lessons on making a sprite move around the screen using go to and move blocks. It then covers topics like turning, repeating movements with loops, and making sprites move smoothly. Later lessons discuss sending and receiving messages between sprites to choreograph their movements, and using forever loops to repeat actions indefinitely. The document concludes by explaining the differences between bitmap and vector drawing modes in Scratch and how this impacts selecting and rotating objects.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30
Chapter 1:
Movement and Loops In this chapter, you will learn
how to build simple scripts to make a sprite move around the stage. LESSON 1.1 Program Name: Square
1. Click File/New to create a new project and enter a
project name of Square. 2. From the Events menu, drag a when green flag clicked block to the scripts area. Your scripts area should look like this:
3. From the Motion menu, drag a go to x: 0 y: 0 block
to the scripts area and snap it to the bottom of the when green flag clicked block. Your script should look like this:
4. Add a move 10 steps block to the bottom of your
script and change the 10 to 100.
5. Click the green flag at the top right corner of the
stage to run your program. Let’s look at what happened: The when green flag clicked block tells Scratch that the other blocks in the script are to be executed at the start of the program — that is, when the green flag is clicked. The go to x: 0 y: 0 block tells Scratch to move the sprite — that’s the cat, which is what you’re writing instructions for — to the coordinates (0, 0). The stage has a coordinate system with (0, 0) in the center, x values ranging from –240 to +240, and y values ranging from –180 to +180. The move 100 steps block tells Scratch to move the sprite 100 units in the direction it is facing. Lesson 1-2: Turning and Waiting Program Name: Square (continued) Now it’s time to make your sprite move in a square. 1. Drag a turn counterclockwise 15 degrees block to the bottom of the script and change the 15 to 90:
2. Add more blocks until you have four move/turn pairs
in your script:
4. Run your program again. Better? If your sprite is too
slow, you can always change the wait time.
Lesson 1-3: Repeat Loops Program
Name: Square (continued)
Look at your script. One thing that should strike you is that three blocks — move, turn, wait — are repeated four times. Imagine if you wanted your cat to walk in a square 100 times. You’d need 1,200 blocks! That’s insane. (Not to mention a lot of work.) Fortunately, there is an easy way to fix this: the repeat loop. 1. Drag the four sets of move/turn/wait blocks away from the bottom of the script. 2. Drag a repeat 10 block to the bottom of your script and change the 10 to a 4. 3. Drag one set of move/turn/wait blocks
3. inside your repeat block. The result should
look like this:
4. Now run your program. Your sprite still
moves in a square, but with far fewer commands. Repeat loops are an incredibly important programming tool. They allow you to repeat actions without having to add extra blocks, thus saving lots of work. Use repeat loops! Lesson 1-4: More Repeat Loops Program Name: Square (continued) You may have noticed that the move block makes your sprite jump from one place to another. Sometimes, this is what you want. Other times, you might want your sprite to move smoothly across the screen. One way to do this is to make it move multiple, shorter distances. 1. Replace the move 100 steps block with a repeat loop that moves the sprite 10 times, moving 10 steps each time. 2. Remove the wait blocks so that the sprite doesn’t pause. (Remember, we added the wait blocks only because the sprite moved too fast to see.) 3. Run your program and watch the sprite move more smoothly in a square. Lesson 1-5: Forever Loops Program Name: Square (continued) What if you want to make your cat really, really dizzy? Or just want to do something forever? There is a special kind of repeat loop for this called a forever loop, which you can find in the Control menu. 1. Replace the repeat 4 block with a forever block. 2. Run your program and watch your cat go round and round and round and round and… Lesson 1-6: Cleanup and Save Program Name: Square (continued) You probably have a lot of unused blocks laying around the script area. 1. Drag the unused blocks to the blocks palette to delete them. 2. Click File/Save to save your project . Chapter 3: Messages In this chapter, you will learn to use messages, which are used to communicate between scripts and between sprites. Sending Lesson 3-1: and Receiving Messages Program Name: Taking Turns 1. Create a new project and name it Taking Turns. 2. Right-click Sprite1 in the sprite list and select duplicate. This will make a copy of Sprite1 named Sprite2. 3. Create a script for Sprite1 that broadcasts the message sprite 1’s turn when the program starts. You will need the broadcast block in the Events menu. To create your message, click the drop-down list, select new message..., and type sprite 1’s turn. Your block should look like this: 4. Drag a when I receive block to the scripts area and set the value to sprite 1’s turn:
5. Add blocks to the when I receive script
to glide to a random position, then broadcast a new message named sprite 2’s turn. You will need the glide 1 secs to x: y: block from the Motion menu, two pick random 1 to 10 blocks from the Operators menu, and a broadcast block. Use the random blocks to choose an x value between –240 and 240 and a y value between –180 and 180. 6. Click Sprite 2. Create a script to receive the message sprite 2’s turn, glide to the position of Sprite1, and broadcast the message sprite 1’s turn. To determine the position of Sprite1, use __ of __ blocks from the Sensing menu, set as follows:
7. Run your program. Sprite1 should glide
to a random position on the stage; Sprite2 should glide to Sprite1’s position; Sprite1 should glide to a new position; and so on. Let’s see what’s happening: a) When the program starts, Sprite1 broadcasts the message sprite 1’s turn. A message is like yelling into a crowd of people, “Who is supposed to wash the dishes?” Everybody can hear it, but only those people (sprites) who have been told they are on dish duty (have a when I receive block for the dish duty message) will respond. This could be zero, one, many, or all people (sprites). b) Because Sprite1 has a when I receive block for the message sprite 1’s turn, it executes the script for that message. In this case, it randomly picks an x value between –240 and +240 and a y value between –180 and +180, then glides to the new position. After gliding, it broadcasts the message sprite 2’s turn. c) Because Sprite2 has a when I receive block for the message sprite 2’s turn, it executes the script for that message. In this case, it finds the x and y coordinates of Sprite1, glides to that position, and broadcasts the message sprite 1’s turn, starting the cycle all over again. Lesson 3-2: Message Practice Program Name: Simon Says A common use of messages is to choreograph animation sequences, where two or more sprites take turns doing something. Use messages to animate a short game of Simon Says between three sprites: the game leader and two game players. For example, the leader might say, “Simon says jump” and both players jump. Or the leader might say, “Turn around!” and one player turns slightly but catches itself and the leader says, “Almost got you.” The game should end with one player winning. Use the say ____ for __ secs block in the Looks menu to have sprites say things. Depending on how you structure your code, you might also want to use the broadcast ____ and wait block in the Events menu. The broadcast ____ and wait block waits until all sprites have finished processing a message before passing control to the next block; the broadcast ____ block passes control immediately to the next block. Chapter 4: Animation Lesson 4-1: Bitmap Mode Before learning animation, you need to learn about two different ways to draw with a computer: bitmap drawing and vector drawing. In this lesson, you will learn about bitmap drawing. 1. Create a new project and name it Bitmap vs. Vector. 2. Click the Costumes tab and click Clear to delete the cat. 3. Look in the lower right hand corner and make sure you are in Bitmap Mode. If you are not in Bitmap Mode, click Convert to bitmap. 4. Using the line tool, draw an X with a short and a long arm: 5. Now suppose you want to rotate the short line while keeping the long line in place. Using the Select tool, select the short line:
6. Using the rotation handle (the circle at
the top of the line coming out of the selection box), rotate the short line:
What happened? Both the short line and a
segment of the long line in the selection box rotated. This is because you didn’t actually select just the short line, you selected everything in the selection box. (Actually, the computer stores a grid of numbers, where each number tells the computer what color to draw each dot in the grid. But it’s easier to think of the computer as just storing a grid of dots.) Because the computer just stores dots, it doesn’t understand anything about those dots. That is, it doesn’t realize that the grid shown above is a line, or that a different grid might show a circle or a triangle. All it sees are dots. As a result, when you use the select tool, you can’t select a particular line in the grid. You can only select the dots in the grid. And when you rotate the grid, you rotate all of the dots in the grid. Lesson 4-2: Vector Mode In the lesson 4-1, you learned about bitmap drawing. In this lesson, you will learn about vector drawing: 1. Click Costume2, clear the canvas, and check that you are in Vector Mode. If you are not in Vector Mode, click Convert to vector. 2. Using the line tool, draw the same lopsided X you drew in the previous lesson. 3. Using the select tool, select the shorter line and rotate it:
What happened? This time, only the
shorter line rotated. The reason for this is the difference between vector graphics and bitmap graphics. In vector graphics, the computer does not store a grid of bits. Instead, it stores information about the actual objects you draw. For example, for a line, it stores the endpoints of the line, as well as the fact that you are drawing a line. For a circle, it stores the center and radius of the circle, and the fact that you are drawing a circle. Because vector graphics store information about individual objects — as opposed to a grid of dots — you can select, rotate, move, and resize individual objects without affecting other objects, even if the objects overlap. In general, you will use vector graphics. Bitmap graphics are useful when creating objects that can’t easily be described by equations, such as the cat sprite or a photograph. However, they are more difficult to work with and this class is about writing programs, not drawing pictures. Name: Hiding Man Sprites can have different costumes, or graphics, for different actions. For example, a sprite might use different costumes for walking, running, and jumping. In this lesson, you will draw four costumes. 1. Create a new project and name it Hiding Man. 2. Click the blue in the upper left corner of the sprite icon, rename the sprite Hiding Man, and click the blue triangle to return to the sprite icon. 3. Click the Costumes tab, clear the canvas, make sure you are in Vector Mode, and use the line and oval tools to draw a simple stick figure of a man walking. Make sure you use separate lines for the body, arms, and legs. This is because we need to reposition the arms and legs later. Don’t spend too much time drawing. We’re learning programming, not fine art. 4. Using the Set costume center tool (the plus sign in the upper right corner of the screen), set the center of the costume to a point on the “ground” just beneath the man’s feet:
A costume’s center is used for
movement and rotation. When you tell a sprite to go to a certain point, its center goes to that point. When you tell a sprite to rotate, it rotates around its center. 5. Click costume2 and delete it, then make two copies of costume1. You can use the stamp tool at the top of the screen, or right click and select duplicate.
6. Click costume2 and use the zoom
controls — the plus and minus in the lower right corner of the screen — to zoom in on your stick man. Rotate and move his arms and legs:
7. Click costume3 and move the arms and legs
again: 8. Finally, click costume2 and duplicate it. You should now have four costumes, with costume2 and costume 4 being identical OTHER INFORMATION IN NEXT PART .