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 – plotting x,y coordinates to draw a square


To complete this exercise, just create a new script in the existing project. That way, we can make use of our custom home block. Let's perform the following steps to do so:

  1. Start the script with the custom home block, and add a pen down block.

  2. Next, we need to add four go to x: () y: () blocks. The coordinates for each block are (100, 0), (100, -100), (0,-100), and (0,0) respectively.

  3. Finish the stack with a pen up block. The following screenshot shows this quick script. As you run this stack of blocks, you'll confirm that you do, in fact, get a square.

What just happened?

I picked an easy example. We're drawing the square by plotting absolute points, meaning we need to know exactly where to position the sprite in terms of its x and y positions in order to get the shape we want. Drawing a pentagon would have been much more difficult. But let's get back to the square.

In previous exercises, we rotated our shape around a center point...