ebook img

Scratch by Example: Programming for All Ages PDF

384 Pages·2016·23.2 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Scratch by Example: Programming for All Ages

Scratch by Example Programming for All Ages — Eduardo A. Vlieg Scratch by Example Programming for All Ages Eduardo A. Vlieg Scratch by Example: Programming for All Ages Eduardo A. Vlieg Curacao, Curaçao ISBN-13 (pbk): 978-1-4842-1945-4 ISBN-13 (electronic): 978-1-4842-1946-1 DOI 10.1007/978-1-4842-1946-1 Library of Congress Control Number: 2016953162 Copyright © 2016 by Eduardo A. Vlieg This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director: Welmoed Spahr Lead Editor: Jonathan Gennick Development Editor: Linda Laflamme Technical Reviewer: Massimo Nardone Editorial Board: Steve Anglin, Pramila Balan, Laura Berendson, Aaron Black, Louise Corrigan, Jonathan Gennick, Robert Hutchinson, Celestin Suresh John, Nikhil Karkal, James Markham, Susan McDermott, Matthew Moodie, Natalie Pao, Gwenan Spearing Coordinating Editor: Jill Balzano Copy Editor: Kim Burton-Weisman Compositor: SPi Global Indexer: SPi Global Artist: SPi Global Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected] , or visit w ww.springer.com . Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected] , or visit w ww.apress.com . Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at w ww.apress.com/bulk-sales . Any source code or other supplementary materials referenced by the author in this text are available to readers at www.apress.com . For detailed information about how to locate your book’s source code, go to www.apress.com/ source-code/ . Readers can also access source code at SpringerLink in the Supplementary Material section for each chapter. Printed on acid-free paper Contents at a Glance About the Author ...................................................................................................xiii About the Technical Reviewer .................................................................................xv Acknowledgments .................................................................................................xvii Introduction ............................................................................................................xix ■ Part I: Learning the Basics .................................................................1 ■ Chapter 1: Getting to Know the Scratch Interface .................................................3 ■ Chapter 2: Meet the Cat .......................................................................................13 ■ Chapter 3: Make the Cat Move ............................................................................37 ■ Chapter 4: Make the Cat Draw .............................................................................59 ■ Chapter 5: The Playful Cat ...................................................................................93 ■ Chapter 6: The Noisy Cat ...................................................................................113 ■ Part II: Becoming a Programmer ....................................................137 ■ Chapter 7: Advanced Concepts ..........................................................................139 ■ Chapter 8: Variables ..........................................................................................185 ■ Chapter 9: Lists .................................................................................................223 ■ Chapter 10: Webcam Interaction .......................................................................249 ■ Chapter 11: Broadcast Interaction ....................................................................271 ■ Chapter 12: Create Your Own Blocks .................................................................301 ■ Chapter 13: Answers .........................................................................................323 ■ Chapter 14: Conclusion .....................................................................................359 Index .....................................................................................................................361 iii Contents About the Author ...................................................................................................xiii About the Technical Reviewer .................................................................................xv Acknowledgments .................................................................................................xvii Introduction ............................................................................................................xix ■ Part I: Learning the Basics .................................................................1 ■ Chapter 1: Getting to Know the Scratch Interface .................................................3 Getting Started .................................................................................................................3 Stage ................................................................................................................................4 Sprites Pane .....................................................................................................................5 Backdrops Pane ...............................................................................................................6 Block Palette ....................................................................................................................7 Scripts Area ......................................................................................................................9 Backpack ........................................................................................................................10 Menu Bar ........................................................................................................................10 Tool Bar ..........................................................................................................................11 Other Important Sections ...............................................................................................11 Summary ........................................................................................................................12 ■ Chapter 2: Meet the Cat .......................................................................................13 Sprites ............................................................................................................................13 Sprites Pane .........................................................................................................................................13 Costumes ..............................................................................................................................................14 Sprites Info Pane ..................................................................................................................................15 v ■ CONTENTS Backdrops ......................................................................................................................27 Backdrops Pane ....................................................................................................................................27 Summary ........................................................................................................................36 Exercises ........................................................................................................................36 ■ Chapter 3: Make the Cat Move ............................................................................37 The Stage .......................................................................................................................37 Scripts ............................................................................................................................39 Motion Blocks .................................................................................................................42 Examples ........................................................................................................................43 Example 3-1: Move Forward .................................................................................................................43 Example 3-2: Move Backward ..............................................................................................................44 Example 3-3: Move Up ..........................................................................................................................45 Example 3-4: Triggered Motion .............................................................................................................46 Example 3-5: Turn .................................................................................................................................47 Example 3-6: Backfl ip ...........................................................................................................................48 Example 3-7: Square Pattern Motion ....................................................................................................49 Example 3-8: Glide and Bounce ............................................................................................................51 Example 3-9: Go to the Mouse-Pointer .................................................................................................54 Example 3-10: Move with the Mouse-Pointer ......................................................................................55 Example 3-11: Point Toward the Mouse-Pointer...................................................................................56 Example 3-12: Follow the Mouse-Pointer .............................................................................................57 Summary ........................................................................................................................58 Exercises ........................................................................................................................58 ■ Chapter 4: Make the Cat Draw .............................................................................59 Pen Blocks ......................................................................................................................59 Examples ........................................................................................................................62 Example 4-1: How to Draw a Line ........................................................................................................62 Example 4-2: How to Draw Lines ..........................................................................................................64 Example 4-3: How to Draw a Square ....................................................................................................66 Example 4-4: Same Square, Different Way ...........................................................................................69 vi ■ CONTENTS Example 4-5: How to Draw a Triangle ...................................................................................................71 Example 4-6: How to Draw an Octagon ................................................................................................74 Example 4-7: How to Draw a Circle ......................................................................................................76 Example 4-8: Circle Art .........................................................................................................................79 Example 4-9: Triangle Art ......................................................................................................................81 Example 4-10: Fill the Circle .................................................................................................................84 Example 4-11: Color the Stage .............................................................................................................86 Example 4-12: Clone the Cat ................................................................................................................89 Summary ........................................................................................................................92 Exercises ........................................................................................................................92 ■ Chapter 5: The Playful Cat ...................................................................................93 Looks Blocks ..................................................................................................................93 Examples ........................................................................................................................96 Example 5-1: Meet the Cat ...................................................................................................................96 Example 5-2: Think ...............................................................................................................................97 Example 5-3: Color Change ..................................................................................................................99 Example 5-4: Colorful Sprite ...............................................................................................................100 Example 5-5: Hide and Show..............................................................................................................101 Example 5-6: Pixelate .........................................................................................................................102 Example 5-7: Change Costume...........................................................................................................104 Example 5-8: Grow and Shrink ...........................................................................................................105 Example 5-9: Shrink and Grow ...........................................................................................................106 Example 5-10: Move and Grow ...........................................................................................................108 Example 5-11: A Short Story ...............................................................................................................109 Summary ......................................................................................................................112 Exercises ......................................................................................................................112 ■ Chapter 6: The Noisy Cat ...................................................................................113 Choosing and Recording Sounds..................................................................................113 Sound Blocks................................................................................................................117 vii ■ CONTENTS Examples ......................................................................................................................119 Example 6-1: Meow ............................................................................................................................120 Example 6-2: Say Meow .....................................................................................................................120 Example 6-3: Play Sound Until Done ..................................................................................................121 Example 6-4: Change Volume .............................................................................................................122 Example 6-5: Let’s Waltz ....................................................................................................................123 Example 6-6: Change Tempo ..............................................................................................................124 Example 6-7: Nursery Rhyme .............................................................................................................125 Example 6-8: The Marching Cat ..........................................................................................................127 Example 6-9: Playing Drums ..............................................................................................................130 Example 6-10: Galloping Horse ..........................................................................................................132 Summary ......................................................................................................................136 Exercises ......................................................................................................................136 ■ Part II: Becoming a Programmer ....................................................137 ■ Chapter 7: Advanced Concepts ..........................................................................139 Control Blocks ..............................................................................................................139 Sensing Blocks .............................................................................................................142 Operators Blocks ..........................................................................................................143 Examples ......................................................................................................................146 Example 7-1: What’s Your Name? .......................................................................................................146 Example 7-2: What’s The Correct Answer? .........................................................................................148 Example 7-3: Please Try Again............................................................................................................150 Example 7-4: Enter Correct Password ................................................................................................153 Example 7-5: Triangle or Square.........................................................................................................154 Example 7-6: Secret Mission ..............................................................................................................158 Example 7-7: Touching the Edge? ......................................................................................................160 Example 7-8: Key Pressed? ................................................................................................................162 Example 7-9: Current Time .................................................................................................................164 Example 7-10: Mouse Coordinates .....................................................................................................165 Example 7-11: Let’s Do Some Math ....................................................................................................167 viii ■ CONTENTS Example 7-12: Math with the Join Block ............................................................................................168 Example 7-13: Guess the Correct Number .........................................................................................170 Example 7-14: How Many Letters in the Word? ..................................................................................172 Example 7-15: Pick a Random Number ..............................................................................................173 Example 7-16: Timer Trigger ...............................................................................................................174 Example 7-17: Move to the Center of the Stage .................................................................................175 Example 7-18: Question......................................................................................................................177 Example 7-19: Can You Solve It? ........................................................................................................179 Example 7-20: Drawing with the Mouse-Pointer ................................................................................180 Summary ......................................................................................................................183 Exercises ......................................................................................................................183 ■ Chapter 8: Variables ..........................................................................................185 Data Blocks and Creating Variables .............................................................................185 Examples ......................................................................................................................188 Example 8-1: Count to Ten ..................................................................................................................188 Example 8-2: Countdown ....................................................................................................................189 Example 8-3: Odd Numbers ................................................................................................................191 Example 8-4: String Variable ..............................................................................................................192 Example 8-5: Draw an Octagon ..........................................................................................................194 Example 8-6: Multiplication ................................................................................................................197 Example 8-7: Guess the Correct Number ...........................................................................................199 Example 8-8: Questions and Answers ................................................................................................201 Example 8-9: How Many Mouse Clicks? .............................................................................................204 Example 8-10: Password and Pin Code ..............................................................................................206 Example 8-11: Only One Correct Answer Required ............................................................................210 Example 8-12: Pong Game .................................................................................................................212 Summary ......................................................................................................................222 Exercises ......................................................................................................................222 ix

Description:
This is a book about learning the Scratch language so that you can use it in teaching and other instructional situations. The book explains the visual nature of the language, showing you how to write programs by dragging and dropping visual blocks representing common compute operations. Scratch is v
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.