Home Programming Scratch 2.0 Beginner's Guide: Second Edition

Scratch 2.0 Beginner's Guide: Second Edition

By Michael Badger
books-svg-icon Book
eBook $32.99 $22.99
Print $54.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $32.99 $22.99
Print $54.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Welcome to Scratch 2.0
About this book
Publication date:
April 2014
Publisher
Packt
Pages
296
ISBN
9781782160724

 

Chapter 1. Welcome to Scratch 2.0

I assume you're reading this book because you want to learn how to create interactive stories, animations, and games using Scratch, or you want to learn Scratch so that you can teach someone else how to program. It matters not whether your classroom is in a middle school, a home school environment, an after-school workshop, or a weekend coding project with your son or daughter. We are all teachers. That's the perspective of this book. You'll learn how to create projects using Scratch so that you can teach someone else, but no programming knowledge is expected.

In this chapter, we will:

  • Review what Scratch is and how we can use it

  • Learn more about the types of projects we will create in this book

  • Explore an example project from the Scratch website and review the project editor

Whether you're 8 or 80, the Scratch programming language provides a beginner-friendly computer programming environment that enables you to create digital projects. Success with Scratch comes quickly. You won't find any quirky syntax to learn, and you won't make any typing mistakes that prevent your program from running.

Creating a project in Scratch is as easy as snapping the color-coded blocks together. This environment allows us to see the positive results quickly. In addition to this, Scratch helps turn passive users into creators.

You'll find comfort in Scratch's building-block approach to create animations, games, and stories. After using Scratch, programming will make sense. It will seem easy. It will bring a smile to your face, and you'll be able to cope with technical concepts in the future.

 

About Scratch


Mitch Resnick and the Lifelong Kindergarten Group at the Massachusetts Institute of Technology (MIT) in the Media Laboratory developed Scratch as a teaching language primarily for 8 – 16 year olds, but there's nothing stopping the rest of us from enjoying the Scratch experience and sharpening our creative minds.

Encouraging everyone to think programmatically

The natural reaction of people is to see Scratch as a means of teaching computer science and integrating it into classrooms of all levels. There are teachers who use Scratch across a variety of subjects as seen on the ScratchEd site. The ScratchEd site caters to the educational community and aggregates a lot of Scratch resources, including lesson plans and tips. However, the approach and thoroughness of the included material varies greatly. You can check out ScratchEd at http://scratched.media.mit.edu/.

While writing this book, I did not set out to write a computer science textbook. It's quite simply a tutorial for people who want to learn how to use Scratch to create stories, animations, games, or art. It primarily addresses the parents, home school families, and teachers who may not be programmers themselves but want a fun way to help their children become more digitally literate. Everyone, however, can use this tutorial to learn Scratch, and many young students have worked through the Version 1.4 of Scratch of this book. I expect young scratchers will be more than capable of working through the projects in this edition.

My underlying belief is that knowing how to program can benefit everyone, but not everyone needs to be a programmer. The mental work required to create a program inherently develops an understanding of how computers work, sharpens our critical thinking skills, and gives us lots of practice at solving problems.

There's also an increasingly popular idea that sometimes we want to create applications for personal use. Of course, system administrators have always created custom scripts to help automate repetitive tasks. However, modern applications such as Scratch or the MIT App Inventor (originally developed by Google) make it incredibly easy to create programs for personal use or with the intention of sharing it with a small group of friends, which counters the perspective that learning to program is synonymous with wanting to be a professional programmer or an application developer.

When you have a little bit of programming knowledge, you'll approach non-programming problems in a different way. For example, I've used programming as a marketer to manage search engine optimization and keyword research on business websites. I've also used my programming knowledge to write automated software tests.

Bottom line, programming becomes a tool in your problem-solving toolbox. This is the key to understanding how I approach this Scratch tutorial. I want the computer scientists to come along for the ride, but I'm catering to a broader audience.

Sample Scratch uses

I couldn't begin to suggest every possible way for you to use Scratch; that's why we have an imagination. However, here are a few ideas to get you started:

  • Use Scratch to teach yourself or your students how to program. That's the obvious one.

  • Use Scratch to demonstrate Math concepts. Scratch can also demonstrate the x and y coordinate system in an interactive way.

  • Use Scratch to inspire your kids to read and write. Find a story and animate each scene or encourage them to animate the story. Turn their haiku into a Scratch project.

  • Have a child who only wants to play video games? Make a deal. Your child can only play the games he creates or remixes with Scratch.

As you work through the examples in this book, write down your project ideas no matter how hard, easy, obvious, or silly they seem. The next one might be your best idea yet.

Computational thinking

Learning: we do it for life. We should help our children develop skills that will help them keep learning and solving problems in an increasingly digital environment. Using Scratch, we will learn how to design, think, collaborate, communicate, analyze, and program in a computer language.

You may frame the Scratch approach as computational thinking. According to Wikipedia:

Computational thinking is a problem solving method that uses computer science techniques. The term computational thinking was first used by Seymour Papert in 1996.

By the time we make our cat dance for the first time, we'll forget all about the academic research and theories behind Scratch. Instead, we'll focus on having fun and creating the next project.

 

Finding a project for you


This book will give you a well-rounded introduction to Scratch. It's true that creating games are incredibly popular, and young boys tend to want to create games. However, there are other uses of Scratch, and plenty of people who want to do something other than just create games. Generally speaking, we'll make an animation, tell a story, build a game, create art, and sense the real world.

Making animations

An animation lets the sprites interact with each other. We'll use the common example of a birthday card to demonstrate animations. The following screenshot shows a birthday card example from Chapter 3, Creaing an Animated Birthday Card:

However, some folks have created more complicated projects using stop-motion animations. You can find some stop-motion animations on the Scratch website at http://scratch.mit.edu/studios/254628/.

Telling stories

The first story project we do will create a slideshow that's designed to be narrated with Scratch's built-in audio capabilities. The following screenshot is a preview of our slideshow:

Our second story project takes a more classical approach to tell a story by creating a book with a table of contents and then animating the individual scenes as a way of narrating the story.

Building games

Games are by the far the most popular Scratch project, and people tend to create all the normal types of games: platformer games, scrolling backgrounds, role-playing games, mazes, and classic arcade games. We'll remix the classic Pong game into a challenging game of Breakout, and in the process, we'll set the stage for many common game-programming concepts. The following screenshot shows the Breakout game:

Programming games of chance

We will encounter randomness throughout the book, but we'll develop a project that applies random outcomes to an interactive story. The following screenshot shows a Trip to the fortune teller:

Creating art projects

The Scratch site is loaded with talented illustrators, and Scratch provides all the tools needed to draw characters and scenes, namely a paint editor and an easy way to animate them. The other kind of art you'll find on the Scratch site is computer-generated art, and we'll spend time drawing geometric shapes, as seen in the following screenshot:

Sensing the real world

Scratch has historically included support for add-on hardware, such as PicoBoard and LEGO WeDo. Scratch also includes built-in support to use the computer's webcam and senses external sounds using the computer's microphone. We'll explore the webcam, microphone, and PicoBoard in our project.

Programming concepts

The following table summarizes several programming concepts that can be learned with Scratch. It's included here primarily to reinforce Scratch as a programming language and foreshadow the concepts we'll use throughout the book. We'll introduce concepts in greater detail as we work through the book.

Concept

Description

Interface design

When we design a program, we turn our imagination into a creation that can be shared with others. We create the flow of the program, how the user interacts with the project, and the actions each sprite takes to tell our story.

Loops (iteration)

A loop repeats (iterates) through a list of programming commands (also known as blocks in Scratch). Often, we'll use conditional statements to control when and how often a loop runs.

Boolean logic

A Boolean command evaluates a given statement as true or false. In Scratch, a Boolean command can check whether a specified condition is true (for example, is the color blue?), or we can compare values with and, or, and not operators. For example, if 4 > 0 and 4 < 2.

Variables

Variables store text or numbers for reuse in the program. For example, if x > 0 creates a conditional statement that evaluates whether the number assigned to x is greater than 0.

Arrays (Lists)

Arrays are similar to variables in that they store information that may or may not change. However, a list stores multiple values in the same way a grocery list stores a group of items.

Events

Scratch provides an entire group of event blocks that allows us to tell our program what to do when that event happens. For example, events include when flag is clicked or when a space key is pressed.

Synchronization and coordination

Programming a sprite to receive a broadcast message from another sprite coordinates a cause and effect. Broadcasting a message and waiting for all the other sprites to act on the broadcast synchronizes the action. Throughout the book, broadcasts are a technique we will use often, and they provide the fundamental communication between the sprites in the project.

Concurrency

Creating two scripts to run on the same control enables parallel execution. For example, programming four different sprites to pixelate when the green flag is clicked creates four concurrent actions.

Random numbers

This concept picks a random number from a specified range.

Cloud data

Scratch 2.0 introduces cloud variables that enable projects to store data on the Scratch web servers so that the data is available to other Scratch users. For example, the use of cloud data might include keeping a high score or tracking the survey results.

Procedures

Procedures can also be called as functions or methods in other programming languages. Scratch 2.0 adds the ability to create custom blocks that allows you to create a stack of blocks under a single name. When you use a custom block, you can pass an argument, such as a sprite number, into the procedure.

Vector and Bitmap graphics

Scratch includes a built-in image editor that enables you to create graphics and sprites for your projects. Vector graphics is a new feature of Scratch 2.0.

Cloning

New to Scratch 2.0, cloning allows a sprite to duplicate itself while the program is running. Clones inherit the parent sprite's costumes and scripts. For example, many people create games that need to shoot something, such as asteroids. Cloning in Scratch 2.0 allows us to shoot multiple times.

Video

By using the computer's built-in webcam, Scratch 2.0 can enable the project to sense the video(s).

 

Using Scratch 2.0


With the release of Scratch 2.0, project creation has primarily moved online. For users who do not have access to the Internet, the Scratch team has launched a complementary offline editor. I'll introduce you to both the environments.

To get started, in your Flash-enabled web browser, go to http://scratch.mit.edu.

Note

For more information about installing Adobe Flash, go to http://get.adobe.com/flashplayer/ in your web browser.

You'll get a page that resembles the following screenshot:

The top of the page contains the Create, Explore, and Discuss links. As we work through our projects, we'll spend our time creating projects, and I'll leave the forum discussions for later. For now, let's just look at a project.

At the time I wrote this chapter, the Following Orange project was displayed as a featured project. It's available at http://scratch.mit.edu/projects/14852464/. If for some reason this project is not available in the future, just click on any project on the Scratch home page and play it. Just experience a Scratch project as a user.

The following screenshot shows the Following Orange project:

When you share your projects with the Scratch community, this is the primary view. It's a relatively intuitive design. The users provide some instructions and credits about the project as seen in the right-half of the previous screenshot. The project displays a green flag in a circle, and clicking on the green flag starts (initializes) the project.

Above the stage, we see the project name with the name of the author (I have no idea who this user is as I just selected it out of convenience). To the right of the project name is a blue See inside button. When you click on See inside, you'll see the project editor.

Looking inside a Scratch project

Clicking on the See inside button for a project will display the details of the project in the project editor, as seen in the following screenshot. If you click on the Create button from the Scratch website, you will open a new project in the same view.

The display gets a little more complicated because there are more things available on the screen, but it's important to note that everything we need to create, test, and run our projects is accessible from the single view of the project editor.

To borrow a phrase from the Scratch Wiki, the project editor is divided into palettes and panes. At this point, I'll draw your attention to three key areas: the stage, the sprites pane, and the script area. Using the Following Orange project as a guide, we'll discuss each one of the three key areas in the following sections.

The stage area

The large space beneath the green flag and the stop sign icons is the stage. This is where our sprites act out their scripts. It's here that we get to see the result of our programming.

The sprites pane

Sprites are the characters and objects in our Scratch projects. The list of sprites can be found below the stage. The following screenshot shows the list of sprites available to the Following Orange project:

The scripts area

In order to get our sprites to animate, move, or interact with one another on the stage, we need to create one or more scripts for each sprite. If you click on a sprite from the list, the project editor will show the existing stacks of blocks in the scripts area.

Tip

A stack of blocks is a script, and a sprite can have multiple scripts assigned to it. In this book, I'll use either script or stack to refer to a collection of blocks.

The following screenshot shows a script for one of the sprites in the Following Orange project:

To create a game, story, or animation in Scratch, we stack blocks together to form a script that gives instructions to the project sprites. In the middle of the project editor screen, we have categories of blocks that are grouped by the kinds of tasks they represent. They are Motion, Looks, Sound, Pen, Data, Events, Control, Sensing, Operators, and More Blocks. Throughout the book, I'll refer to these categories of blocks as palettes; they can be seen in the previous screenshot.

The palettes of blocks are analogous to the palette of colors an artist mixes while creating a painting. We mix the blocks together to form our art work. Each type of block is color coded so that we can easily identify them by their type in our scripts.

The commands written on the blocks are in plain English, and they don't require a lot of effort to understand the basic idea behind any block. Take the script visible in the previous screenshot as an example. You might not know exactly what these two scripts do, but by reading the blocks, you will generally understand that these blocks are initializing the game and changing to the next level.

The built-in image editor

One of the core features of Scratch is its built-in image editor, which allows us to draw our own backgrounds and sprites. This makes it incredibly easy for users to create sprites and project backgrounds, and it's readily available from the project editor.

Previous versions of Scratch used a bitmap image editor, but as of Version 2.0, Scratch can also draw in vector graphics, which allows us to create images that are smooth and scalable to any size.

The following screenshot shows the default Scratch cat in the paint editor. If you've used any image editor in the past, including GIMP or Photoshop, then the drawing tools should have a familiar feel to them.

Scratch's built-in paint editor is relatively basic in terms of the number of features, but is functional for most of our uses. In general, the paint editor will allow you to perform the following tasks:

  • Create shapes and text

  • Import and edit images in popular formats

  • Apply color

  • Resize and change the orientation of the image

The image editor is available from multiple points within the Scratch interface, as we'll see throughout the book. We'll cover the paint editor in greater detail in Chapter 3, Creating an Animated Birthday Card.

Using Scratch 2.0 offline

It's not possible to be connected to the Internet all the time, which may be an increasingly difficult idea to accept for some people. Nevertheless, consider that your Internet connection may go down, that the Scratch website may be offline for updates, or perhaps your Internet connection is slow.

If you can't get to the Scratch website, then you can't create a project using the online project editor. Thankfully, the Scratch team has released an offline editor. You can download it from http://scratch.mit.edu/scratch2download/.

The download page includes an online installer that will install the prerequisite software, namely Adobe Air, on your computer. The following screenshot shows the Scratch 2 Offline Editor:

As we see, the offline editor looks like the online editor. Using the offline editor, you can create projects and then share them to the Scratch website. We'll review sharing projects in Chapter 2, A Quick Start Guide to Scratch. The offline version of Scratch 2.0 has been in development for several months following the official release of Scratch 2.0.

The previous screenshot indicates that the editor shown is beta. Be sure to double-check the download page for information pertaining to the functionality and release stability of the offline editor. I would highly recommend downloading the offline version as a backup to the online version. While the Scratch team does make a great effort to protect user privacy, creating and saving projects offline does not require an account on the Scratch website, ensuring user privacy.

Encountering Scratch 1.4

One of the biggest limiting factors of Scratch 2.0 is its reliance on Flash and Adobe Air (for the offline version). Not all computer systems are capable of running Flash environments; some Linux users and users of the low-cost, credit card-sized Raspberry Pi come to mind. The Pi is a Linux-based computer that's capable of plugging into an existing television set and keyboard. The Pi and Linux versions in general run Scratch 1.4. My XO laptop also runs Scratch 1.4.

All of these Flash challenges increase the likelihood of encountering Scratch 1.4. I do not insist on the use of Scratch 1.4 until we come across the PicoBoard projects in Appendix A, Connecting a PicoBoard to Scratch 1.4; however, if you're a Scratch 1.4 user, most of these projects can be adapted with little effort. I've taken the effort to specifically identify features that are exclusive to Scratch 2.0 so that users of the older versions can adapt appropriately.

Tinkering encouraged

The structure of the Scratch interface makes it easy for us to tinker and explore ideas. As we create projects, we evaluate our work and determine whether the results meet our expectations. It's very easy because everything happens in one interface.

To check whether our project works, we don't have to compile the code, switch windows, upload files to a server, or work around any number of other obstacles to run our project. Scratch enables us to modify the program as it runs and see the results in real time.

 

Summary


In this chapter, we reviewed Scratch both in terms of its possibilities and how it's used in the book to create stories, animations, games, and art. Whether you're a mom, a dad, a workshop facilitator, or a young scratcher, this chapter lays the foundation for the work we'll do in the rest of the book. We've even explored a project and the project editor.

In the next chapter, we'll create an online Scratch account, explore the community, and then move right into our first Scratch project. It'll give us an easy way to tinker with the Scratch interface and take our first steps. We'll focus on some project management fundamentals including naming objects, sharing projects, and lots of things in between.

About the Author
  • Michael Badger

    Michael Badgeris a writer and technical communicator who has worked in a range of technical roles, including support, automated software testing, and project management. He has authored several books for Packt Publishing, including Scratch 1.4 Beginner's Guide. He also authors a regular Scratch column for Raspberry Pi Geek Magazine, which focuses on Scratch 1.4.

    Browse publications by this author
Latest Reviews (3 reviews total)
Es uno de los lenguajes de programación más fáciles de aprender pero es mejor si se tiene la correcta asesoria.
Scratch 2.0 Beginner's Guide: Second Edition
Unlock this book and the full library FREE for 7 days
Start now