with
The Basics of Scratch for Everybody of All Ages
by Seamus O’Neill
Scratch Copyright (c) 2009 Massachusetts Institute of Technology Scratch is developed by the Lifelong Kindergarten group at the MIT Media Lab. See http://scratch.mit.edu The Scratch logo and the Scratch cat are trademarks of MIT.
About the Author: Seamus O'Neill is a former primary teacher and co-author of Mathemagic, Ireland's most popular and best-selling primary Maths programme since 2002. He has totalled over 50 years teaching experience with teacher training and is a prolific developer of online interactive learning resources. In June 2017 the Scratch team at the MIT Media Lab accorded Seamus unique and honourable distinction when they added his fine-line vector grids into the Scratch Backdrop library. He brings a wealth of experience and a razor sharp focus on what actually works for modern teachers.
For Breda B
Š Seamus O’Neill 2017 We and Us Ltd. Educational Design Services Navan, Co. Meath, IRELAND
In June 2017, the MIT Media Lab (Boston) added Ready-Steady-Code grids directly into the Scratch the Backdrop library. These vector grids on a bitmap stage are a magic mix that gives Scratch new functionality and make it the world leading free teaching resource for Computational Thinking in 21st century classrooms. The 3 main vector grids:
xy-grid-10px*
xy-grid-20px
xy-grid-30px
*The 10px grid is not in the Backdrop library. Download it from https://scratch.mit.edu/projects/104133413
All rights reserved. No part of this publication may be reproduced or transmitted, in any form or by any means, electronic, mechanical, photocopying or otherwise, without the prior permission of the author and publisher.
Why Learn Scratch? One often hears about the various projects aiming to get young people involved in computing and for various reasons. Jobs! Computing is on the curriculum! 21st century skills! And so forth. But there are lots of fun and valuable things to learn besides coding, and of course, there are many demands on teachers’ time. So why learn Scratch code? The first answer I have for you is not earth-shattering, but it's an honest one. Just like taking a cookery class. Everybody should try it at least once. Give Scratch an honest try and see if you actually enjoy it! You might see a catch here – isn't learning to code much harder than going to a casual cookery class? After all, Computer Science is a deep, academic subject with numerous real-world applications. Many people fear a steep, frustrating learning curve, achieving nothing but esoteric skills. Why might this book open an opportunity and not some kind of obligation? Scratch has been compared to a modern tool for creative expression, like a paintbrush for canvas, a pen for paper. Are paintbrushes, paint, copybooks, pens and pencils on the curriculum? Do we have lessons about pencils? Aren't they just resources we use daily and enjoy, without much thinking about them? That is where Scratch with Ready Steady Code come in. Scratch is especially designed for people to enjoy coding, young or old. Scratch is a highly visual and colourful place to programme in, full of quirky characters and sound effects. Ready Steady Code makes Scratch the new copybook and pencil. It can be used by kids or by the teachers, tutors or parents working with the young people. This book will bring you on a learning journey that starts from scratch (pun intended!) and focuses on creativity, fun and enjoyment in a topic everyone would like to get behind, Maths with Computational Thinking. So, this gives rise to a second answer. It’s told by a friend as a humble and personal story about how learning to code was genuinely enjoyable, challenging and satisfying. She tells her story. “I started coding because I wanted to understand statistics better. I was not in it for the joy of coding; I quite assuredly assumed coding wasn't for me”. She went on to say how she proved herself wrong, just to show that you never know when the penny will drop, and because it's a funny story. She had some extra time in bed, but her phone battery had died and she had no alarm on her laptop. She lay in bed thinking, there must be some way to set an alarm. And then she thought maybe she could programme one... You can see her alarm on the right. Think about what each of the different 'blocks' of code does. Perhaps there are ways it could be improved. She enjoyed her extra half-hour snooze. How she achieved it had a huge feel-good factor. Try it yourself now! I wish you every satisfaction on the learning journey you're about to take, and hope you share your enjoyment with others. Seamus O’Neill Ready Steady Code
This alarm, she says, was her first ‘proper’ bit of code.
i
Contents PART 1: The Basics of Scratch How to Use Part 1 of This Book
1
The Grey and Yellow Pages
Exercise 1:
Getting Started
3
The Scratch Project Editor
Exercise 2:
Get a Scratch ID
5
Can I use Scratch 2.0 offline?
Exercise 3:
Create and Save Your First Scratch Script 7 What's in the Sprite Info Pane?
Exercise 4:
Thinking, Speaking Sprites
9
Toolbar Symbols
Exercise 5:
ii
Duplicate a Sprite and its Script
11
Sprites have Costumes; the Stage has Backdrops
Exercise 6:
Make a Simple Game (Shark Screech)
13
Where are the Sounds in Scratch? Is the IF ..THEN block a loop?
Exercise 7:
Colour a Vector Graphic
15
Vector Graphics vs. Bitmap Graphics
Exercise 8:
Programme a Conversation
17
Learn About Some Code Blocks
Exercise 9:
Finding Missing Numbers
19
What is a Variable?
Exercise 10:
Code a Number Objective Project
21
Can You do Sums With the Operator Blocks?
Exercise 11:
Mouse and Cheese Game
23
Need a Sprite that’s not in the Sprite Library? (Exercise 12)
Exercise 12:
Draw a Vector Image (Piece of Cheese) Alternatively, save an image from a shared Scratch project.
24
PART 2: Essential Coding Skills with the SCRATCH Palettes
The Plan of Part 2 of This Book
25
There is an A2-size 10 Palettes Wall Chart to Support the Exercises in Part 2
Exercise 13:
The Sprite Library
26, 27
Learn More About Bitmap and Vector Sprites
Exercise 14:
Animate, Move and Turn Sprites
29
PALETTES: Motion, Events, Looks and Control
Exercise 15:
Make one Sprite Point Towards Another
30
Programme a Sprite’s Direction, Rotation and Size
Exercise 16:
Move an Apple Sprite with the Keyboard
31
Move Around the Stage Using the Direction Keys on the Keyboard
Exercise 17:
Animate Candles on a Birthday Cake
33
PALETTES: Sound, Sensing, Pen and Operators
Exercise 18:
Musical Instruments: Compose Music
34
Explore the Musical Instruments of the Sound Palette
Exercise 19:
Draw and Code a Xylophone to Play
35
Explore the Notes of the Sound Palette
Exercise 20:
Code a Sprite to Draw with its Pen
36
Change the Sprite’s Direction While it Draws
Exercise 21:
Pen Essentials and Programming Fun
37 - 39
Draw Simple Designs with the Pen Commands Blocks
Exercise 22:
Programme the Pen to Draw 2D Shapes
40
Square, Pentagon, Hexagon, Octagon and Circle
Exercise 23:
Plot a Circle from its Centre and Radius
41
Draw Filled Circles and Pie Graphs
Exercise 24:
Draw a Square in Scratch and on Paper
42
Working with Coordinates
Exercise 25:
Rotating Squares with Nested Loops
43
Number of Repeats and Amount of Turning
Explore the Operators Palette Further
44, 45
OPERATORS: Plus/Minus/ Multiply/ Divide / Mod and Round
Exercise 26:
Report the Position and Direction of a Sprite 46 Using the Join Operator (to Con-cat-en-ate) join Different Types of Data together
iii
Exercise 27:
Exploring the Operators Palette (continued)
47
The Equality and Inequality Operators
Exercise 28:
The Sprite that tells its Own Location
48
Learn Basic Coordinates on the Scratch Stage
Exercise 29:
Code a Number Objective Project (SUMS)
49
Programme Order of Operations with Animated Sprites
Exercise 30:
Variables and Lists in the Data Palette
50, 51
Make the Sprite recite the Multiples of any Number
Exercise 31:
Dinosaur Tables Test
52
Input Your Own Numbers and Multiply
Exercise 32:
Make the Sprite Recite Times Tables
53
Use a Variable in Slider Mode
Exercise 33:
Question and Answer Lists
54
Create a Number Quiz with Worded Questions
Exercise 34:
Create a Picture Quiz
55
Two Lists and Questions using Pictures on the Backdrop
iv
Exercise 35:
Create a Test Against Time
56
Base a Times test on Two Parallel Lists of Random Numbers
Exercise 36:
Make Rows and Columns of Apples
57
What it is to Clone a Sprite
Exercise 37:
Rows and Columns of 3 Sprites
58
Base on Random Selection of Fruit
Exercise 38:
Vary the Lengths of Shapes
59
Use a Variable in Slider Mode to Draw Various Shapes
Exercise 39:
A New Block to Draw a Triangle and Square
61
PALETTES: More Blocks. Define a New Block to Draw a Line
Exercise 40:
A New Block to Draw a Circle
62
Define a New penSetup Block
Exercise 41:
Use Nested Procedures
63
Draw Petals and Flower Designs using Procedures (New Blocks)
Exercise 42:
Re-use a Procedure and Add a Variation Correlate Coding with Drawing a House in a Copybook
There is an A2-size 10 Wall Chart to Support Part 2
64
PART 3: Scratch and Maths with the fine-line Vector Grids
The Plan of Part 3 of This Book
65
NUMBERS You Should Know About the Scratch Stage. Make Scratch Resemble Squared Paper
Exercise 43:
Draw a Square in Scratch and on Paper
67
Use a squareSize Variable
Exercise 44:
Draw a Triangle in Scratch and on Paper
68
Use a squareSize Variable
Exercise 45:
Draw and Code Regular Shapes
69
Correlate Coding with Drawing Shapes and Angles in a Copybook
Exercise 46:
Draw with the Pen Using the Keyboard
70
When it’s Necessary to Lift and Move the Pen
Exercise 47:
Draw Regular Shapes Together
71
Correlate Coding with Drawing Shapes and Computational Thinking
Exercise 48:
Calculate the Area of Rectangles in Sq Units
72
Correlate Coding with Calculating Area and Perimeter
Exercise 49:
Code a Circle and its Area
73
Work out its Area by Counting Squares on Squared Paper
Exercise 50:
Code a Line Sprite to Rotate
74
Draw the Line in the Scratch Paint Editor and Set its Rotation Point
Exercise 51:
Code a Protractor to Measure Angles
75
Correlate Scratch Code with Angle Measurement
Exercise 52:
Types of Angles
76
Make the Monkey Say the Type of Angle
Exercise 53:
Code a Pie Chart
77
Correlate with Data Collection and Representation
Exercise 54:
Code a Block Graph to Show 20 Rolls of a Die 79 Draw a Gaming Die Sprite
Exercise 55:
Layout and Code a 6-Horse Race Game
80, 81
Use Grids to Make Layout Easier
Save and Upload a Shared Backdrop
82
Save and Upload a 10 pixel Graph-paper Backdrop
Exercise 56:
Demonstrate Secondary Level Graphs in Scratch
83-86
Example 1: Graph a Linear Equation / Example 2: Graph a Quadratic Equation
v
PART 4: Animation and Integration with the PAINT EDITOR Exercise 57:
Layout a Mother’s Day Animation
88, 89
Show How Grids Make Layout Easier
Exercise 58:
A Game for Juniors Made by Seniors
90, 91
Create a New Sprite: Draw a Lily Pad
Exercise 59:
Create an Interactive Graphic
92
A Frog With and Without a Tongue
Exercise 60:
The Anatomy of a Vector Sprite
93
Ungroup, Duplicate, Rotate and Group a Vector Sprite
Exercise 61:
Create a Cartoon-type Animation
94, 95
Draw and Code a Fly Sprite
Exercise 62:
Dance to a Beat
96
Create a triple Nested Loop
Exercise 63:
Dress Up the Cat for the Snow
97
Animate a Snowfall
vi
Exercise 64:
The Magic Carpet and Rings Game
98, 99
Create Elements of a Game in Paint Editor
Exercise 65:
Shark Chomp
100 -102
Node Editing in Vector Graphics
Exercise 66:
Grids for Drawing Paths and Designs
103
Draw Yor Own Maze
Exercise 67:
Flags and Other Drag and Match Games
104, 105
Use Grids to Layout a 4x3 Drag-and-Match Game
Exercise 68:
Puzzle Challenges
106, 107
The 9-Dot Puzzle and Other Challenges
Exercise 69:
Tell the Story of the Fox and the Crow
108, 109
Animate any Well Known Story
Exercise 70:
The Disappearing Submarine Make a Submarine Disappear and Reappear using Abs
110