Getting Comfortable with the Scratch Interface
6. Sprites Pane: In case you wondered, a sprite is a graphical object that you include in your
Scratch app. By default, the Scratch Cat appears as a sprite in all new Scratch projects. You can import existing graphics as sprites or draw your own from, well, scratch.
To get started, visit the Scratch Projects site (http://is.gd/tsr9gM) and download somebody’s project that looks interesting. Again, you need to be logged in with your Scratch account to download projects (see Figure 8.4).
FIGURE 8.4 You can try out and download other peoples’ Scratch projects directly from your web browser.
It bears repeating that you cannot preview projects in a browser on Raspi because the Pi does not
support Adobe Flash. Moreover, my communication exchanges with Eben tell me that the Raspberry Pi Foundation has no future plans for the Pi to support Flash.
The main Scratch Projects website contains only Scratch 2.0 projects. Although you can upload your Scratch 1.4 projects to the website, they will be converted to Scratch 2.0 before they appear on the website. You can then edit the uploaded projects directly in your web browser (unfortunately, you can’t run Scratch 2.0 projects from Scratch 1.4).
The traditional way to start a Scratch project (whether from a web browser or from within Scratch itself) is to click the Green Flag icon in the Stage area. By contrast, you can use the Red Stop Sign icon to manually stop the project.
One of the awesome things about open source software such as Scratch is that you can go beyond simply admiring other Scratchers’ projects—you can actually view their source code and base your own Scratch projects off of that code.
Let’s spend some time getting to know how the actual programming code works in Scratch. To that point, you need to understand what blocks are and how they are used.
About Blocks
As I said earlier, you can use these easy-to-understand blocks to actually program your Scratch app.
As you’ll learn soon enough, blocks are puzzle-type pieces that “snap” together in much the same way that LEGO blocks do.
These blocks make it easier for beginning programmers to think about and execute programming logic without having the additional burden of learning programming language syntax.
In the Scratch interface Blocks palette, blocks are arranged in the following eight categories:
Motion: These blocks enable you to position a sprite on the Stage and optionally move or glide it around. Click Edit, Show Motor Blocks to reveal extra blocks intended for use with the LEGO Education WeDo Robotics Kit (http://is.gd/HIquiE).
Looks: These purple blocks allow you to change the look (called a Costume) of your sprites.
You also can have a sprite “say” or “think,” as well as ask the user for feedback.
Sound: These pink blocks give you control over system volume and allow your sprites to make sounds of their own.
Pen: These dark green blocks enable your sprites to draw vector lines onscreen.
Control: These gold blocks represent the brains of your Scratch app. You can start scripts, stop scripts, and manage all events within the program by using Control blocks.
Sensing: These light blue blocks are used to detect input from the user. For instance, you can detect mouse clicks, typed responses, and analog events inbound from a PicoBoard. (I’ll tell you more about the PicoBoard momentarily.)
Operators: These light green blocks perform mathematical equations and are also used to handle string data.
Variables: These blocks are used to make two types of variables: traditional variables and lists (formally called arrays).
I don’t notice this because I am profoundly colorblind, but I’m sure you observed that blocks within each type are color-coded. This helps you associate certain types of actions with certain types of blocks. Moreover, the color-coding helps you keep your variables distinct from each other within your program.
Note: What is a Variable?
A variable is nothing but an in-memory placeholder for a piece of data. Computer programs use variables, which can dynamically change their stored values (hence the name variable), to move data around inside an application.
Scratch blocks themselves fall into six shape types:
Hat blocks Stack blocks Boolean blocks Reporter blocks C blocks
Cap blocks
Figure 8.5 displays representative examples of each block type. Take a look at them, and then let’s learn a little bit more about each block shape.
FIGURE 8.5 A mash-up showing you the different types of block shapes in Scratch. Here’s a key to the annotations: 1: Hat block; 2: Stack block; 3: Boolean block; 4: Reporter block; 5: C block; 6:
Cap block.
Hat Blocks
Hat blocks have rounded tops, which indicate that they are used to initiate actions, not follow other actions. The Green Flag hat block is universally used to start scripts. I myself also use the Broadcast hat blocks a lot to send and receive messages among different parts of my Scratch app.
Stack Blocks
Stack blocks typically form the bulk of your Scratch programming logic. You can see by the notch at the top and bump at bottom (like interlocking puzzle pieces) that Stack blocks can have blocks attached above and below, forming, well, stacks of programming logic.
Boolean Blocks
Boolean blocks are used to represent binary (yes/no, on/off, true/false, 0/1) conditions in your program. You’ll note two things about Boolean blocks:
They have sharp edges.
They cannot be stacked, but instead are placed inside of Stack blocks as arguments.
Because Boolean blocks report values (namely true or false), they are also considered Reporter blocks.
Reporter Blocks
Reporter blocks hold values. Like Boolean blocks, Reporter blocks fit inside of other blocks rather than stack themselves. Visually, Reporter blocks have rounded ends as opposed to the sharp ends of Boolean blocks.
C Blocks
C blocks derive their name from their visual appearance. These blocks wrap around one or more other blocks. For instance, you can use a Forever C block to perpetually repeat one or more actions throughout the runtime of the application.
Alternatively, you can apply true/false conditions to C blocks such that their enclosing actions run only as long as the root expression evaluates to True.
Cap Blocks
Cap blocks are used to stop individual scripts or all scripts within the app. You’ll see visually that Cap blocks have smooth bottoms and notched tops, which clues you in instantly as to their purpose.