Wikijunior:Raspberry Pi/Introduction to Scratch
Scratch is a visual programming language developed by the Massachusetts Institute of Technology (MIT) to introduce programming concepts to children.
Installing Scratch
[edit | edit source]Scratch is preinstalled on Raspberry Pi OS (and its predecessor Raspbian) by default.
Online Scratch 3 editor
[edit | edit source]You will need to create a Scratch account to save the programs you make with the online editor. |
There is an online editor on the website that can be used for the tutorials which should work on most modern web browsers such as Google Chrome (and its open-source counterpart Chromium), Microsoft Edge, Apple Safari, Opera and Mozilla Firefox.
Offline Scratch 3 editor
[edit | edit source]Alternatively, you can also download a copy of the offline editor from the official website. Scratch 3 officially supports these operating systems:
- Microsoft Windows 10 and Windows 11 via the Microsoft Store or direct download
- Apple macOS 10.13 (High Sierra) and later via the Mac App Store or direct download
- Google ChromeOS via the Google Play store
- Google Android 6 (Marshmallow) and later via the Google Play store
You can also install Scratch 3 on Windows 10 and Windows 11 via the Winget command in Windows PowerShell: winget install -e --id MITMediaLab.Scratch.3
Alternative Linux distributions
[edit | edit source]If you use an alternative Linux distribution to Raspberry Pi OS, you may need to install Scratch using the package manager via the Terminal:
- Debian and Ubuntu:
sudo apt install scratch
- Fedora:
sudo dnf install scratch
- Arch:
sudo pacman -Syu scratch
Try some simple programs
[edit | edit source]A simple "Hello World" program
[edit | edit source]Creating a "Hello World" program in Scratch 3 is very simple:
- From the Events category, select and drag the yellow "when clicked" block.
- From the Looks category, select and drag the purple "say 'Hello!'" block.
- Change the text in the purple block from "Hello!" to "Hello World".
- Click the Go button (with the green flag icon ) to start the program.
This is equivalent to writing print("Hello World")
in the Python programming language.
Moving a sprite
[edit | edit source]Moving a sprite is essential for making games and other animations. To move a sprite in Scratch, follow these steps:
- Add a sprite to your project.
- From the Events category, select and drag the yellow "when clicked" block.
- From the Motion category, select and drag the "move 10 steps" block.
- Click the Go button (with the green flag icon ) to start the program.
- Watch as your sprite moves 10 steps to the right.
You can change the number in the "move 10 steps" block to make your sprite move faster or slower. You can also drag other motion blocks, such as "turn 10 degrees" and "go to x: 100 y: 100", to make your sprite move in different ways.
Making a sprite jump
[edit | edit source]This is a more advanced Scratch concept, but it's still relatively easy to learn. To make a sprite jump in Scratch, follow these steps:
- Add a sprite to your project.
- From the Control category, drag a "when clicked" block category to the Scripting Area.
- From the Control category, drag a "wait 1 second" block to the Scripting Area and place it inside the "when green flag clicked" block.
- From the Motion category, drag a "change y by 10" block to the Scripting Area and place it inside the "wait 1 second" block.
- From the Motion category, drag a "change y by -10" block to the Scripting Area and place it below the "wait 1 second" block.
- Click the Go button (with the green flag icon ) to start the program.
- Watch as your sprite jumps into the air and then falls back down.
You can change the number in the "change y by 10" and "change y by -10" blocks to make your sprite jump higher or lower. You can also add more "wait 1 second" blocks to make your sprite stay in the air for longer.
Further reading
[edit | edit source]There are several books on Scratch.
The ScratchJr book is aimed at a younger audience from the age of 5+ and has its own accompanying app which is available for Apple iPad (App Store) and Android tablets (Google Play and the Amazon appstore).
Make Your Own Scratch Games! is aimed at the age of 10+.
Title | Author | Year | ISBN |
---|---|---|---|
Make Your Own Scratch Games! | Anna Anthropy | 2019 | ISBN 978-1593279363 |
The Official ScratchJr Book: Help Your Kids Learn to Code | Marina Umaschi Bers, Mitchel Resnick | 2015 | ISBN 978-1593276713 |
Wikibooks has a book on Scratch though it is incomplete.