Learn… Create… Program
What is Scratch?
Scratch is a free programmable toolkit
that enables kids to
create their own games, animated
stories, and interactive art
share their creations with one another
over the Internet.
© Department of Studies, Group
Head Office, The City School. 2
What is Scratch?
Scratch builds on the long tradition of
Logo and LEGO/Logo, but takes
advantage of new computational ideas
and capabilities to make it easier for
kids to get started with programming
(lowering the floor) and to extend the
range of what kids can create and learn
(raising the ceiling).
© Department of Studies, Group
Head Office, The City School. 3
What is Scratch?
The ultimate goal is to help kids
become fluent with digital media,
empowering them to express
themselves creatively and make
connections to powerful ideas.
© Department of Studies, Group
Head Office, The City School. 4
What is Scratch?
Increase student skills with computers
Increase student interest in
programming
Student achievement on fun project
Learn Cartesian coordinates, distance
computations, etc.
© Department of Studies, Group
Head Office, The City School. 5
Computer scientists
Create solutions to problems using
computers
Study information
Invent algorithms
Write programs to implement the
algorithms
Reuse a lot of existing program and
machine parts
© Department of Studies, Group
Head Office, The City School. 6
Start scratch and let’s go!
Click on the cat icon
Or, find “scratch” under “Programs”
When home, download from
www.scratch.mit.edu
Scratch programming environment
comes up quickly
© Department of Studies, Group
Head Office, The City School. 7
Click on the
“Looks”
button at
the top left.
© Department of Studies, Group
Head Office, The City School. 8
Major components
At right: the stage with sprite[s] or
objects or actors
At left: operations and attributes for the
sprites
Center: scripts or program[s] for the
behavior[s] of the sprites
Your sprites are actors that you direct
with your scripts
© Department of Studies, Group
Head Office, The City School. 9
Let’s implement an algorithm
to average two numbers
Make a
variable
“number1”
(click and
drag and
set)
Make
another
one
“number2”
© Department of Studies, Group
Head Office, The City School. 10
Compute average first as sum
Make variable
average
Drag a “set
operation” to script
area
Drag a + operation
Drag variables
number1 and
number2 to
parameters
Click to execute
© Department of Studies, Group
Head Office, The City School. 11
Average script as 4 operation
sequence.
Change the two
numbers and click
the sequence to
execute the block
again.
© Department of Studies, Group
Head Office, The City School. 12
But Scratch computes with
multimedia – color, sound, …
Can make cartoons
Can create stories
Can create video games
© Department of Studies, Group
Head Office, The City School. 13
The “hello” script
Can do it in 57 languages – java, C++,
… Scratch
Easy in Scratch: select “Looks”
operations and drag the “hello operation”
onto your center panel.
Then double click on this “lego block”:
check your sprite behavior at the right
Your very first Scratch program!
© Department of Studies, Group
Head Office, The City School. 14
Make the cat 50% larger
1. Select “Looks” operations
2. Drag the “change size” operator into your
script
3. Click and edit for a 50% change (increase)
4. Double click your one operation script
5. Did your©cat spriteofget
Department 50%
Studies, bigger?
Group
Head Office, The City School. 15
Scripting a sequence of ops
Do ops in the following order by
dragging operation blocks into a single
connected block
Say hello
Move 200 steps forward
Grow 50% bigger
Make the “meow sound”
© Department of Studies, Group
Head Office, The City School. 16
Some new operations
•color
change
(Looks)
• wait
(Control)
• move
(Motion)
© Department of Studies, Group
Head Office, The City School. 17
Starting a looped script
© Department of Studies, Group
Head Office, The City School. 18
Exercise: write a script to
Make the cat move along a square path
Say “hi” at all four corners
Wait 3 seconds at each corner
Change color at all four corners
Double size when back to the original
starting location.
Say “That’s all folks” when done.
© Department of Studies, Group
Head Office, The City School. 19
Elements of Scratch: objects
Colors
Sounds
Locations in 2D space
Sprites
Costumes
Variables (to remember the state of things)
Events: that are broadcast for communication
© Department of Studies, Group
Head Office, The City School. 20
Elements of Scratch: control
Sequence of operations
Loops or repetition
Detecting events (key or mouse
pressed, sprites overlapping each other,
sprites hitting edge of stage, sensor
giving value)
© Department of Studies, Group
Head Office, The City School. 21
Loop constructs in Scratch
Repeat N times
Repeat forever
Repeat forever if
some condition
exists (suppose I’m
a sprite wandering
about this lab until
someone asks a
question)
© Department of Studies, Group
Head Office, The City School. 22
Conditions can be checked
Do something if
sprite k hits sprite m
Do something if a
certain key is
pressed
Do something is
some variable takes
a certain value
© Department of Studies, Group
Head Office, The City School. 23
Interacting with your sprite or
story
Using mouse
Entering a character
Asking the user a question
© Department of Studies, Group
Head Office, The City School. 24
Sprite follows the mouse
Try changing
the number of
steps or the
wait time.
© Department of Studies, Group
Head Office, The City School. 25
Play and examine MadLib
Choose the “file” option at the top of
the window
Choose “open”, then “examples”
Choose “stories”
Choose “MadLib” and then read the
authors instructions
Click OK, wait for load, click green flag
© Department of Studies, Group
Head Office, The City School. 26
About the MadLib story
How many actors (sprites)?
What is the role of the girl?
How are the answers you give 'remembered'
and then used in later actions?
What is the role of the little whale?
What makes the little whale flip around?
What makes the big whale spout?
© Department of Studies, Group
Head Office, The City School. 27
Sprites can interact with each other
Can detect when colors overlap in space
Can detect when sprites bump into
edge of the stage
See “bouncing balls” example under
Simulations under Examples
Interact with this simulation
Check out the rather complex scripts
© Department of Studies, Group
Head Office, The City School. 28
Check out the break dance
Open examples; music and dance;
break dance
How does break dancing begin?
What are the roles of the sprites?
What events are in the scripts?
What should happen when the boom
box is clicked?
© Department of Studies, Group
Head Office, The City School. 29
Experiment with Scratch as
time permits
Try your own scripts: make moves, sounds,
interactions in simple cases
Try the examples and learn what makes them
work
Download Scratch on your own machine and
experiment some more
Direct a story; or a simulation; or create a
video game.
© Department of Studies, Group
Head Office, The City School. 30