Book Image

Scratch 2.0 Beginner's Guide: Second Edition

By : Michael Badger
Book Image

Scratch 2.0 Beginner's Guide: Second Edition

By: Michael Badger

Overview of this book

Table of Contents (18 chapters)
Scratch 2.0 Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – enabling the user to create custom shapes


In this exercise, we're going to create variables and enable user-entered values via sliders:

  1. Create four variables named sides, length, angle, and pen size. This automatically adds a stage monitor for each variable.

  2. Hide the angle stage monitor. We're going to turn the other monitors into slider controls. Right-click on each monitor and select slider, as shown in the following screenshot:

  3. Next, add a set () to block from the Data palette as the first block after the when (d) key pressed block. We want to calculate the angle of the shape by dividing 360 by sides. The set () to block becomes set (angle) to (360/sides).

  4. Add the sides reporter block to the repeat block.

  5. Add the length reporter block to the move () steps block.

  6. Add the angle reporter block to the turn () degrees block.

  7. Insert the set pen size to () block above pen down. Add the pen size block as the size value in set pen size to ().

  8. The script looks like the following screenshot...