Starting from
An Introduction to Computing Science
by Jeremy Scott
Scratching the Surface
LEARNER NOTES
Starting from Scratch An Introduction to Computing Science
Acknowledgements
This resource was partially funded by a grant from Education Scotland. We are also grateful for
the help and support provided by the following contributors:
Cathkin High School
Linlithgow Academy
Perth High School
George Heriot’s School
Stromness Academy
CompEdNet, Scottish Forum for Computing Science Teachers
Computing At School
Professor Hal Abelson, MIT
Mitchel Resnick, MIT
Scottish Informatics and Computer Science Alliance (SICSA)
Edinburgh Napier University School of Computing
Glasgow University School of Computing Science
Heriot-Watt University School of Mathematical and Computer Sciences
University of Edinburgh School of Informatics
Robert Gordon University School of Computing
University of Dundee School of Computing
University of Stirling Department of Computing Science and Mathematics
University of West of Scotland School of Computing
International Olympic Committee
ScotlandIS
Turespaña
Brightsolid Online Innovation
JP Morgan
Microsoft Research
Oracle
O2
Sword Ciboodle
The contribution of the following individuals who served on the RSE/BCS Project Advisory Group
is also gratefully acknowledged:
Professor Sally Brown (chair), Mr David Bethune, Mr Ian Birrell, Professor Alan Bundy, Mr Paddy
Burns, Dr Quintin Cutts, Ms Kate Farrell, Mr William Hardie, Mr Simon Humphreys, Professor
Greg Michaelson, Dr Bill Mitchell, Ms Polly Purvis, Ms Jane Richardson and Ms Caroline Stuart.
Some of the material within this resource is based on existing work from the ScratchEd site,
reproduced and adapted under Creative Commons licence. The author thanks the individuals
concerned for permission to use and adapt their materials.
BCS is a registered charity: No 292786
The Royal Society of Edinburgh. Scotland's National Academy. Scottish Charity No. SC000470
i
Starting from Scratch An Introduction to Computing Science
Contents
Introduction .................................................................................................... 5
What is a computer? ...................................................................................... 5
Types of computer ......................................................................................... 6
Parts of a computer ....................................................................................... 9
Hardware ..................................................................................................... 10
Software ....................................................................................................... 11
Programming languages .............................................................................. 12
Programming in Scratch ................................................................................ 13
1: Scratching the Surface ............................................................................... 15
All the world’s a stage .................................................................................. 15
Putting things in order ................................................................................. 17
Did you understand? .................................................................................... 18
Lazy or smart? .............................................................................................. 20
2: Story Time ................................................................................................. 21
Bugs .............................................................................................................. 22
Event-driven programming .......................................................................... 25
3: A Mazing Game ......................................................................................... 27
The Importance of Design ............................................................................ 27
4: Get the Picture? ........................................................................................ 35
Nesting ......................................................................................................... 36
5: Forest Archery Game ................................................................................. 43
Variables....................................................................................................... 46
Summary ...................................................................................................... 49
Scratch Project .............................................................................................. 51
Congratulations ............................................................................................ 60
iii
Starting from Scratch 1: Scratching the surface
1: Scratching the Surface
This lesson will cover
x The Scratch environment, including
o Sprites & stage
o Properties
Scripts
Costumes/backgrounds
Sounds
x Creating a program with animation & sound
Introduction
Watch the video introduction to Scratch. This will introduce you to Scratch and its
screen layout.
http://www.youtube.com/watch?feature=player_detailpage&v=jxDw-t3XWd0
All the world’s a stage
A Scratch program contains sprites (characters) that “perform” on a stage. Sprites and
the stage have three kinds of properties (or settings):
1. Scripts
These are the instructions that control a sprite. Scripts are made from blocks.
There are eight different kinds of blocks – to do with motion, control, looks, etc.
– and over 100 blocks in total. Note that sprites need scripts to perform a task.
2. Costumes/Backgrounds
Costumes are “outfits” for a sprite. The same sprite can have several costumes
and so be made to look completely different.
The stage can have different backgrounds which can be changed. Backgrounds
are just like costumes for the stage.
3. Sounds
These are sounds that sprites or the stage can use. Again, each sprite (or the
stage) can have many different sounds. Scratch lets you import (bring in)
recorded sounds or even record your own using a microphone.
Page 15
Starting from Scratch 1: Scratching the surface
Task 1: Up on the Catwalk
Watch screencast Catwalk.
This will go over the main elements within Scratch and take you through the task of
creating your first computer program. If you get stuck, go back in the screencast or ask
your partner.
Task 2: Frère Jacques
Watch screencast FrereJacques.
This will show you how to create a simple tune in Scratch. If you get stuck, go back in the
screencast or ask your partner.
Did you know…? Frère Jacques is one of the best-known songs in the world. It is a French song about a
religious monk (“Brother John” in English) who has the job of ringing the morning bell
before the days of alarm clocks. Unfortunately, poor Jacques has overslept!
Task 3: My Tunes
Once you have completed Task 2, try creating a program that plays another simple song.
Choose one where lines of the music repeat, so you can use the repeat command.
Congratulations – you have just started your journey to become a computer
programmer!
Page 16
Starting from Scratch 1: Scratching the surface
Putting things in order
Blocks in the same script get executed (carried out) in sequence, one after the other.
Blocks in separate scripts can sometimes be executed at the same time. This is called
parallel processing – having the computer do more than one thing at a time.
For example, if you have several scripts, they will all get executed together
when the green flag is clicked.
Extension 1: Dance away
Try to make a sprite dance in time to your music, starting the program when the green
flag is clicked. There are two ways you could do this:
x create a single script that includes the sprite movement blocks amongst the
play note blocks
x have separate scripts for the same sprite – one script plays the tune whilst the
other makes the sprite dance.
You can find another screencast (Dancing Queen) to give you some inspiration at
http://info.scratch.mit.edu/node/164 .
Make sure you create a tune, rather than just use a music loop, though!
Extension 2
Experiment by adding some other blocks to your program, such as the looks blocks e.g.
These let you create some really fun effects!
Page 17
Starting from Scratch 1: Scratching the surface
Did you understand?
1.1 Look at the section of code opposite that controls a sprite.
Write down what you think the user will see when the
green flag is clicked.
__________________________________________________________________
__________________________________________________________________
Why? _____________________________________________________________
__________________________________________________________________
Now try out the code yourself and see if you were right.
1.2 Now add a wait 1 secs block between the two move blocks. Describe what
happens now.
__________________________________________________________________
Explain why this happened ____________________________________________
__________________________________________________________________
1.3 Look at the section of code below that controls a sprite.
Write down what you think the user will see when the green flag is clicked.
__________________________________________________________________
__________________________________________________________________
Why? _____________________________________________________________
__________________________________________________________________
Now try out the code yourself and see if you were right.
Page 18
Starting from Scratch 1: Scratching the surface
1.4 In the stack of blocks below, how many times does the sprite move 10 steps?
__________________________________________________________________
1.5 A programmer wants the cat to dance to some music. However, the cat doesn’t
start dancing until after the music has finished!
Why is this?
__________________________________________________________________
__________________________________________________________________
Page 19
Starting from Scratch 1: Scratching the surface
1.6 In the example below, a programmer has chosen a piece of music (sound
“Xylo1”) to play during a game. However, when the green flag is clicked,
the computer just plays the first note of the music – over and over again!
What mistake has the programmer made?
__________________________________________
__________________________________________
1.7 In Extension 1: Dance Away, you made a sprite dance to a tune you created.
There were two ways you could do this:
x have a single script with the movement blocks amongst the play note blocks
x have separate scripts for the same sprite – one script plays the tune whilst the
other makes the sprite dance.
Why do you think experienced programmers would use separate scripts?
__________________________________________________________________
__________________________________________________________________
1.8 Make up a question like those from 1.1–1.6 and pass it to your neighbour.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
Lazy or smart?
Computer programmers always look for shortcuts to make their life easier.
A good example is how we used a repeat block in Frère Jacques to repeat the same line
of music instead of having two identical sets of blocks. As well as looking neater, it also
means that you won’t make a mistake when creating a second set of blocks.
Do you think this makes programmers lazy or smart? (Hint: the answer is smart!)
You can make your life easier, too by spotting shortcuts like this.
Page 20