Animation

With Scratch you can easily animate sprites. Many sprites already have multiple costume. You can give the impression of walking or flying by simply alternating between two different costumes.

Flying sprites

https://scratch.mit.edu/projects/391871367

The Bat sprite has 4 costumes. You can delete the 4th one (sleeping) and just keep the 3 flying costumes.

../_images/bat_costume.png

Want multiple bats in the sky. Therefore we are going to make clones. Note that we do not anymate the original. We only use it to make clones. At the end we hide the original.

Inside I loop we

  • go to a random position
  • choose a randome size
  • choose a random costume
  • make a clone
../_images/bat_clone.png

In order to give the impresion to fly, we change the costume every 0.3 seconds.

../_images/bat_fly.png

To move the bats around on the screen, we let them glide to random positions, every 1-3 seconds.

../_images/bat_glide.png

Moving chickens

The following example shows how to animate chickens.

https://scratch.mit.edu/projects/395241257

At the start we set the rotation style to left-right because we do not want the hens to be upside down.

Inside the loop we:

  • go to a random position (avoding the cabbin and the far back)
  • switch to a random costume
  • set a size which depends on y
  • create a clone
../_images/hen_start.png

For each cloned hen we do this in a loop:

  • switch to the next costume
  • wait 1-2 seconds
  • randomly move to the left or to the right
  • randomly point to the left or to the right
../_images/hen_start.png

Animate a play

Wouldn’t it be interesting to use Scratch to create a theater play. Let’s take the first scene from Alice in Wonderland from the Gutenberg project.

https://www.gutenberg.org/files/35688/35688-h/35688-h.htm

Scene 1 : Alice’s home

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
Alice’s home. Lewis Carroll is discovered, playing chess. Golden-haired Alice, in a little blue dress, a black kitten in her arms, stands watching him.
Alice
That’s a funny game, uncle. What did you do then?
Carroll
A red pawn took a white pawn; this way. You see, Alice, the chessboard is divided into sixty-four squares, 
red and white, and the white army tries to win and the red army tries to win. It’s like a battle!
Alice
With soldiers?
Carroll
Yes, here are the Kings and Queens they are fighting for. That’s the Red Queen and here’s the White Queen.
Alice
How funny they look!
Carroll
See the crowns on their heads, and look at their big feet.
Alice
It’s a foot apiece, that’s what it is! Do they hump along like this?
Carroll
Here! You’re spoiling the game. I must keep them all in their right squares.
Alice
I want to be a queen!
Carroll
Here you are [he points to a small white pawn] here you are in your little stiff skirt!
Alice
How do you do, Alice!
Carroll
And now you are going to move here.
Alice
Let me move myself.
Carroll
When you have traveled all along the board this way and haven’t been taken by the enemy you may be a queen.
Alice
Why do people always play with kings and queens? Mother has them in her playing cards too. Look!
[Alice goes to the mantel and takes a pack of playing cards from the ledge.]
Here’s the King of Hearts and here’s his wife; she’s the Queen of Hearts—isn’t she cross-looking? wants to bite one’s head off.
[Carroll moves a pawn.]
You’re playing against yourself, aren’t you?
Carroll
That’s one way of keeping in practice, Alice; I have friends in the university who want to beat me.
Alice
But if you play against yourself I should think you’d want to cheat!
Carroll
Does a nice little girl like you cheat when she plays against herself?
Alice
Oh! I never do! I’d scold myself hard. I always pretend I’m two people too. It’s lots of fun, isn’t it? 
Sometimes when I’m all alone I walk up to the looking glass and talk to the other Alice. 
She’s so silly, that Alice; she can’t do anything by herself. She just mocks me all the time. 
When I laugh, she laughs, when I point my finger at her, she points her finger at me, and when I stick my tongue out at her she sticks her tongue out at me! 
Kitty has a twin too, haven’t you darling?
[Alice goes to the mirror to show Kitty her twin.]
Carroll
I’ll have to write a book some day about Alice—Alice in wonderland, “Child of the pure unclouded brow and dreaming eyes of wonder!” or, Alice through the looking glass!
Alice
Don’t you wish sometimes you could go into looking-glass house? See!
[Alice stands on an armchair and looks into the mirror.]
There’s the room you can see through the glass; it’s just the same as our living-room here, only the things go the other way. 
I can see all of it—all but the bit just behind the fireplace. Oh! I do wish I could see that bit! 
I want so much to know if they’ve a fire there. You never can tell, you know, unless our fire smokes. 
Then smoke comes up in that room too—but that may be just to make it look as if they had a fire—just to pretend they had. 
The books are something like our books,[Pg 5] only the words go the wrong way. Won’t there ever be any way of our getting through, uncle?
Carroll
Do you think Kitty would find looking-glass milk digestible?
Alice
It doesn’t sound awful good, does it; but I might leave her at home. She’s been into an awful lot of mischief today. 
She found sister’s knitting and chased the ball all over the garden where sister was playing croquet with the neighbors. 
And I ran and ran after the naughty little thing until I was all out of breath and so tired! I am tired.
[She yawns and makes herself comfortable in the armchair.]
Carroll
[Replaces the playing cards on the mantel and consults his watch.]
Take a nap. Yes, you have time before tea.
Alice
[Half asleep.]
We’re going to have mock turtle soup for supper! I heard mamma tell the cook not to pepper it too much.
Carroll
What a funny little rabbit it is, nibbling all the time!
[He leans gently over the back of her chair, and seeing that she is going to sleep puts out the lamp light and leaves the room. 
A red glow from the fireplace illumines Alice.]
[Dream music. A bluish light reveals the Red Chess Queen and the White Chess Queen in the mirror.]
Red Queen
[Points to Alice and says in a mysterious voice.]
There she is, let’s call her over.
White Queen
Do you think she’ll come?
Red Queen
I’ll call softly, Alice!
White Queen
Hist, Alice.
Red Queen
Alice!
White Queen
Hush—if she wakes and catches us—
Both Queens
Alice, come through into looking-glass house!
[Their hands beckon her.]
Alice
[Rises, and talks sleepily. The Queens disappear. 
Alice climbs from the arm of the chair to the back of another and so on up to the mantel ledge, where she picks her way daintily between the vases.]
I—don’t—know—how—I—can—get—through. I’ve tried—before—but the glass was hard—and I was afraid of cutting—my fingers—
[She feels the glass and is amazed to find it like gauze.]
Why, it’s soft like gauze; it’s turning into a sort of mist; why, it’s easy to get through! Why—why—I’m going through!
[She disappears.]

Download: alice.txt

Scenario

The most important point here is to work with lists. We have two main lists:

  • Scenario
  • Actors

Fortunately we can import and export lists. Let’s prepare the dialog in a text editor.

  • remove the emply lines
  • break dialog into lines of less then 128 characters (which is the limit for text-to-speech)
  • place the actor’s name on a single line
  • followed by one more multiple lines of dialog for that actor
../_images/alice_scenario.png

So far we have 3 actors:

  • Alice
  • Carroll
  • Red Queen

We use Capitalized names. These names will also figure in the Actors list.

../_images/alice_sprites.png

Only sprites can show text. We use the broadcast message read line to

  • set the voice for that actor
  • show the dialog text in a bubble
  • pronounce it with text-to-speach
  • turn off the speech bubble
../_images/alice_speak_line.png

At the start we

  • set the language to English.
  • set the index to 1
  • set the actor to empty
  • switch to the title background
../_images/alice_start.png

To read a single line, we load the current Scenario line into the variable line. If the line contains exactly the name of an actor in the Actors list, we set the actor variable and proceed.

Otherwise we translate the line of dialog and send the speak line broadcast.

../_images/alice_read_line.png

Pressing the SPACE bar will perform just the current line of dialog.

../_images/alice_do_line.png

Pressing A (All) will perform the whole play from the beginning to the end. .. image:: alice_all.png

https://scratch.mit.edu/projects/391344110