39,59 €
Scratch 2.0 is an easy to use programming language that allows you to animate stories and create interactive games. Scratch also gives you the capability of using programming to calculate complicated calculations for you.
Scratch Cookbook will lead you through easy-to-follow recipes that give you everything you need to become a more advanced programmer.
Scratch Cookbook will take you through the essential features of Scratch. You'll then work through simple recipes to gain an understanding of the more advanced features of Scratch.
You will learn how to create animations using Scratch. Sensory board integration (getting input from the outside environment) will also be covered, along with using Scratch to solve complicated and tedious calculations for you. You'll also learn how to work through the exciting process of project remixing where you build on the work of others.
Scratch Cookbook will give you everything you need to get started with building your own programs in Scratch that involve sounds, animations, and user interaction.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 256
Veröffentlichungsjahr: 2013
Copyright © 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: July 2013
Production Reference: 1170713
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84951-842-0
www.packtpub.com
Cover Image by Sandeep Vaity (<[email protected]>)
Author
Brandon Milonovich
Reviewers
David Busby
Stamati Crook
Andrew Johns
Martina Kabátová
Pedro Neves Rito
Forest Y. Yu
Acquisition Editor
Joanne Fitzpatrick
Commissioning Editor
Llewellyn Rozario
Lead Technical Editor
Anila Vincent
Technical Editors
Shashank Desai
Krishnaveni Haridas
Mausam Kothari
Pushpak Poddar
Rikita Poojari
Amit Ramadas
Project Coordinator
Hardik Patel
Proofreaders
Maria Gould
Paul Hindle
Indexer
Monica Ajmera Mehta
Graphics
Ronak Dhruv
Production Coordinator
Aparna Bhagat
Cover Work
Aparna Bhagat
Brandon Milonovich completed his Master's degree in Teaching and Curriculum with emphasis in Mathematics Education in December 2012 at Syracuse University in central New York. Prior to attending Syracuse, Brandon earned his Bachelor's degree in Adolescent Mathematics Education at The College of Saint Rose in Albany, NY. Brandon grew up in upstate New York with an interest in mathematics and computer science at a young age. Brandon has experience of teaching mathematical concepts to students using Scratch in third through fifth grade, as well as experience of teaching mathematics at the middle school, high school, and university level.
It was during Brandon's time at Saint Rose that he began his work with Scratch through an internship program with Computer Science professor Helen Albanese. In coordination with three Albany City School District teachers, Brandon developed an after-school program centered on programming in Scratch for at-risk youth. The program expanded the following year to include a broader age range of students. Now, Brandon works towards making learning Scratch more accessible within the classroom itself, both with traditional methods and flipped classroom-blended learning style concepts, to build the mathematical foundation students need to be successful 21st century learners. Brandon believes in sharing of information as broadly as possible, and so has presented with his colleagues at numerous conferences and workshops on Scratch, and hopes to continue to do so.
For more information on Brandon, or to contact him, visit http://www.bmilo.com.
I would like to thank all of those who have helped me along the way in both the process of writing this book, as well as becoming qualified to write it. Special thanks to Helen Albanese for her continued pushing to work more with Scratch and the opportunities she has provided, as well as a thank you to every professor I had at both the undergraduate and graduate level who have guided me along the way. Thanks also to the Albany City School District for opening its classrooms, particularly to Laurie Ellis, Stephen Costello, Alice Florence, and Timothy Fowler. The greatest thanks of all to my family for their constant support, guidance, and help. Without the amazing group of people I've been surrounded by throughout my life, I would have had little chance of success.
David Busby has been a Linux system's admin for around 12 years now and almost always being in a varied role over the years be it development, network admin, support, DBA changing onto a day-to-day basis.
Whenever time permits, he contributes to the EPEL packages for OpenStack and generally follows OpenStack's progress as much as possible.
He has an interest in Infosec, and as a result is generally paranoid about security. He is also familiar with Metasploit, sqlmap, john, and oclHashCat, and has also written a few python tools, and experimented in Golang.
He holds a 2nd Dan black belt in Ju-Jitsu and assists with teaching at a local non-profit club. He also helps to teach a computing class for children at a local school, using Raspberry Pi.
Stamati Crook is a professional programmer with his own software house and consultancy on the south coast of England. He has been involved in teaching Scratch to children at local primary schools and also hopes that his own three children will begin to show more interest in creating games rather than just playing them. His wife, Kathy, also uses Scratch daily in her classroom and you can find lesson plans and resources for children, parents, and teachers learning and teaching Scratch at http://www.redware.com/scratch.
Andrew Johns has been a web developer since 1999. He became a STEM Ambassador and Code Club volunteer in 2012, teaching Scratch to primary school children. He currently works for London-based design agency, Pretty, as a Technical Lead. This is the first book for which he has acted as a Technical Reviewer.
Martina Kabátová is a teacher and a researcher in the field of Computer Science education. After completing her PHD, she began to work as an Assistant Professor at Comenius University in Bratislava, Faculty of Mathematics, Physics and Informatics, Department of Informatics Education. Among her responsibilities are several university lectures on programming, educational robotics, and research methodology. Currently, she focuses on educational programming (especial for very young children). She is an author of several study materials and many conference papers dealing with various aspects of Computer Science education. In 2013, she co-authored a book Transforming Schools in Digital Age, with Prof. Ivan Kalaš, which summarizes the role of digital technology in education. Martina Kabátová also illustrated this book and she is the author of many illustrations for other computer science textbooks, educational software, and MicroWorlds, and for the Slovak Bebras contest for children in informatics.
Pedro Neves Rito has been working as a professional trainer in the area of information technology and communications for more than 16 years, and as a teacher in higher education for the last six years. He has a Master's degree in Multimedia in Education and is currently a student of the Doctoral program in information systems and technologies. He has used Scratch as a tool for an introduction to programming. Lately, he's been exploring physical computing and Scratch, particularly the use of the Arduino, with the perspective of building activities for primary students. This work has been developed with the help of teachers of different levels of education.
He is currently also an assistant professor at Polytechnic Institute of Viseu, at the School of Education, working in the Department of Communication and Art, in the area of Information Technology and Communication. He works with higher education students, particularly in plastic arts and multimedia, and those pursuing primary education courses (future teachers) and also some that are pursuing Master's courses. In addition to being a teacher in these areas, he has supported a few initiatives outside school that are related to the use of Scratch.
He has started some individual projects, including the writing of two books, which is ongoing. In recent years, he has dedicated most of his time to contributions, by publishing and presenting scientific articles at conferences and some other documents to print media.
Forrest Y. Yu is an author of two books on operating systems. He has a wide range of interests and experiences, including desktop applications, web services, LBS, operating systems, cloud computing, and so on. Recently, he has been working with Amazon building the next generation information security platform and tools. He has a blog http://forrestyu.com/ where you can find more information about him.
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
If you're relatively new to programming, or are just looking for a programming language that allows you to explore your visual and creative side, Scratch will be a lot of fun for you. Scratch was developed as a project of the Lifelong Kindergarten Group at the MIT Media Lab to make programming more accessible to young and/or new programmers.
As you work through this book, you'll gain a greater understanding of how to work with Scratch while simultaneously developing an understanding of fundamental programming principles that you'll want to know when you eventually begin to work with other programming languages.
You'll notice pretty quickly that this book is written focusing on Scratch 2.0, the newest version of Scratch. Don't worry though if you're still working in Scratch 1.4, the Scratch creators did a nice job keeping consistency between versions, so the differences won't be too challenging.
This book was written to be read in small bits at a leisurely pace or for an extended period of time in one sitting, it's up to you. Each chapter focuses on a specific aspect of Scratch and is broken down into easy to follow recipes. While most chapters make use of previous skills you've learned up to that point in the text, you don't necessarily need to read each chapter in order. Each recipe begins with the explicit steps you need to accomplish the goal of the recipe, follows with an explanation, then ends with some other ideas you may wish to explore on your own.
Lastly, the best way to learn Scratch (or any new programming language for that matter) is to not be afraid to play around as you go. Be sure to unleash your creative side; all you need is this book, a computer with Scratch, and your mind!
Chapter 1, Getting Started with Scratch, introduces the basics you'll need to know as you start working with Scratch. This chapter builds the foundation for the work done in all the other chapters and will help you get comfortable with Scratch.
Chapter 2, Storytelling, covers what you need to begin telling stories in Scratch, extending upon the animation techniques from.
Chapter 3, Adding Animation, tells us that Scratch is great for working with media; this is the chapter where you work with bringing some basic animation techniques into your programs.
Chapter 4, Basic Gaming, explains some of the first steps in creating a game in Scratch, as mostly everyone likes to create games.
Chapter 5, Spicing up Games, expands on the principles from the last chapter on games. This chapter spices things up while also bringing up some techniques you'll use for other programming.
Chapter 6, Bringing in Sound, covers adding and working with sounds in your programs.
Chapter 7, Integrating PicoBoards, explains how to get your sensor board working, as well as some fun programs to work with the board.
Chapter 8, Programming to Calculate, works with some of the techniques that make some tedious programming tasks easy.
Chapter 9, Project Remixing, covers taking projects in one form and transforming them. We'll examine this idea while also exploring other odds and ends in Scratch.
Appendix, Collaboration, covers how you can collaborate and share with other scratchers, as one great aspect in Scratch is to be able to share.
We don't have to work with too much software for Scratch. We'll be working with Scratch 2.0 for the most part, which runs directly out of your browser. This requires any one of the following browsers:
Along with the browser, you should have Adobe Flash Player Version 10.2 installed (there is a good chance you already have all of this). If you don't have the ability to update your current software to meet these requirements, you can also download Scratch 1.4 from http://scratch.mit.edu/scratch_1.4/. We go into more detail on getting started with Scratch in the first chapter.
You can also find the requirements for using Scratch on your computer at http://scratch.mit.edu/help/faq/.
This book is intended for a wide variety of audiences. You should be familiar with operating your computer pretty comfortably, and it would be helpful if you've seen Scratch before, though that is not required. If you've worked with Scratch quite a bit, it may be worthwhile to skip the first chapter, though there will be plenty to explore in the rest of the chapters.
For extra book content, visit http://www.bmilo.com/ScratchCookbook.
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "You'll notice that we imported the first four that are available in the Outdoors folder, and deleted the default white background".
New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Place a forever loop directly underneath, from the Control category".
For blocks where you as the programmer need to place a value, words, or something else, you'll notice we indicate that with parentheses. An example of this is the move () steps block from the Motion category.
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the erratasubmissionform link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.
In this chapter, we will cover the following recipes:
This chapter explains all you need to know to get started when working with Scratch. We'll be focusing on using the latest version of Scratch, Scratch 2.0. Scratch gives young programmers the flexibility to develop programs of all types, many of which will be explored throughout this book. This chapter is meant to get you used to working with the Scratch interface before we dive into the more challenging topics involved. Note that if you have worked with Scratch some time before, you may wish to move on to Chapter 2, Storytelling. If you are new to Scratch, or have been away for quite some time, this chapter is just the right place to get started! For more information on getting started, it might be helpful to visit the Scratch resources at http://scratch.mit.edu/help.
This first recipe to follow, which will help you download and install Scratch to your computer. Follow along and you'll be using Scratch in no time.
Our first recipe is all about getting Scratch up and running. Scratch can easily be used on any computer. Simply visit http://scratch.mit.edu/help/faq/ to see the requirements for Scratch. If you've used Scratch 1.4 before, you'll recall that you had to install Scratch on your computer. The Scratch creators have made it even easier to use Scratch 2.0. Now you can run Scratch directly within your browser. All you need is a recent browser and Adobe Flash Player!
Although Scratch can be installed on Mac, Windows, and Linux, in this book all of the instructions will be tailored to using a Windows-based system with Scratch 2.0. The commands should be the same, just keep this in mind if you are using a different system.
To use Scratch 2.0, simply click on the Create link on the Scratch home page. If you want to use Scratch 1.4, follow these steps. The installer will create a link on your desktop for you as well as a Start menu shortcut. Follow these steps to download and install Scratch:
Once you're inside Scratch, play around with the interface. Scratch is broken up into three main areas that you'll be working in. These are called the Block Palette, Script Area, and Stage. These three areas are labeled in the following screenshot:
In Scratch 2.0, you'll see these areas in the following manner:
So, what are these three areas all about? How do I use them to build programs?
Each of these areas helps in a different way to build your program. The Block Palette is your library of commands, which you can add to your program. To build programs, all you need to do is drag and-drop these to your Script Area. Notice that there are eight categories of blocks. Each of these is color coded and does something different. We will explore more and more of these with each program we create!
The script area is vital to each individual program. A sprite is an object in Scratch we will program (usually characters). The default is the cat seen in the preceding screenshot. Each sprite as well as the background have their own Script Area, where you can drag blocks from the Block Palette. With more complicated programs, you need to drag more and more of these blocks to the Script Area.
A few examples of sprites you might use in your program are:
The last area of the Scratch interface is probably your favorite: the Stage. Here is where everything you've programmed comes together, and then you can see it in action. Just below the Stage is the collection of all the sprites you've added to your program, this is how you select those individual script areas we mentioned before. Once we get past our first program, most of the magic will happen after you click on the green flag up in the right-hand corner of the stage. You can also stop everything by clicking on the little red button next to the green flag.
Now that you have a basic understanding of the interface of Scratch, we can move on to customizing some of the fun things we'll be programming. Our next recipe, Deleting the default sprite features importing, adding, and changing sprites. See the rest of the recipes in this chapter as well for further basic information you'll need to program with Scratch.
As we mentioned before, sprites are the objects you program. They are the characters to your stories, players of your games, and everything in between. When you first open up Scratch, the default sprite is the cat (the one seen in the screenshot of the interface). You may want to use that sprite, or import a different one or more of them. We'll start by deleting the default sprite.
Later in this chapter, we are going to create our first program with Scratch: Hello World. All of our recipes in this chapter will lead up to this. Let's get this setup by customizing our environment. All you have to do to get this recipe ready is open up Scratch. This recipe is all about getting rid of the default sprite so that you can import others.
Follow through this series of steps to get rid of the default sprite that Scratch opens with:
You can use these tools in the script area as well with your programming blocks when you build your programs.
