Programming with Scratch
As a homeschooling parent, I'm a big fan of educational software and I've written quite about about various programs in the past. But, as a programmer, I'm also a big fan of any program that makes computer programming more approachable by younger children. So, when I heard about Scratch, I was pretty enthusiastic. (Thanks, Mitch)
Scratch allows the user to write programs by dragging and connecting simple programming instructions. The programming instructions resemble puzzle pieces and will only “fit” together in ways that make semantic sense. For example, you can't put the “Start” instruction inside an “If” instruction. The instruction pieces are also color-coded according to what type of instruction they represent; all control structure pieces are yellow, while all motion pieces are blue. The program that the user creates controls one or more objects, or sprites. From a programmer's perspective, Scratch has a very sophisticated set of instructions, as we'll see soon.
Scratch comes with a number of example projects that provide a fairly broad sample of what can be done with Scratch.
Once a user has created a program that they like, they can share their project with others via the Scratch Web Community at scratch.mit.edu. As I write this, just under 1.1 million projects are available for download! Some of these projects are obviously done by young users and are very simple. Others are quite sophisticated.
Broadly speaking, Scratch projects fall into 3 different categories. Some projects are simply animations or stories that play out within Scratch. One of the example animations that come with Scratch tells the story of a little girl who is so frustrated by email spam that she calls her Congressman to suggest that a law be created to outlaw sending spam. The Congressman proposes the law, The House signs it. The Senate modifies it and sends it to the President. It's just a neat little story. Obviously, there wasn't any intense programming needed.
The Interactive Art projects range from kaleidoscopes, to paint programs, to dress-up games. The kaleidoscope example project lets the user move a cursor around the canvas using the arrow keys. The program then duplicates the user's movements to create interesting patterns.
Then there are the game projects. In about an hour, I whipped up a simple Pong program. Others have “whipped up” 3D combat flight simulators! One of the more simple, but engaging games that I found was a virtual obstacle course where you guide a little green ball around with the mouse and try to avoid moving obstacles. This was a very simple game, but I spent more time playing it than I care to admit.
The Scratch user interface is intuitive, though perhaps a bit limited. (Figure 1.) The interface breaks out cleanly into 3 columns. The left column is what you might refer to as a “pallet” that contains the various instructions that the user can choose from to build a program. At the top of the pallet is a group of buttons that select which type of instructions to display below. Here you can see that the “motion” instructions have been selected.
The right column of the interface is divided into two parts. The top part is the “stage” where all of the action takes place. The bottom part contains one or more sprites that are used in the program. By selecting a sprite, the user can then write a program to control the sprite's actions.
The center column is where the actual programming takes place. The user simply drags programming instructions from the pallet into the center column and connects them together to build up one or more programs that control the current sprite, which is displayed at the top. (Figure 2.) The current sprite can also be resized and rotated as needed.
As I implied earlier, each sprite can have one or more programs that control it's behavior. Typically, you'd have a main block that runs when the program starts. You could also have a block of instructions that run when the user presses the left arrow key; this block of code might move the sprite to the left, or it might cause the sprite to “fire” a weapon. Other blocks of code may execute when a sprite receives a certain message, either from another block of code, or from another sprite. My Pong game has a message handler that responds to the “score” message that gets broadcast whenever either player scores a point. The message handler simply resets the ball in the center of the field and starts it moving again. But by having multiple blocks of code running, either as main blocks, keyboard handlers, or message handles, you can write very sophisticated programs.
Scratch includes several different sprites in quite a few different categories. However, the user can also import their own graphics or use the built-in sprite editor. The build-in sprite editor is just like most pixel-based paint programs. The user has a selection of colors and tools to choose from and can rotate and resize a given sprite as needed.
Finally, each sprite can have multiple “costumes.” A costume is essentially a different version of a given sprite, perhaps in a different pose, or with a “power-up” affect applied. By switching costumes, the user can create, characters that appear to walk, characters that wear armor, or balls that appear to spin as they move. A sprite's costumes can be activated from within the programming.
In addition to having multiple sprites at once, Scratch allows you to change the background from within a program. This capability can be used to create different levels of a game or different scenes in a story, for example. Different backgrounds can be created in the same ways that sprites are created from within Scratch.
As you can see, there is a lot to talk about before we even discuss the programming institutions available to the user. As mentioned earlier, the programing institutions are broken down into eight categories. The “motion” instructions move and rotate a sprite in different ways. In the “looks” category, we find instructions for changing a sprite's costume and color. We also find instructions that allow the sprite to “say” and “think” messages to the user. In the sounds category, we find instructions for playing drum sounds as well as 128 different instruments and sound affects. The pen institutions give the user the ability to draw lines under program control, much like the Logo programing language. The control category is where we find our control structure instructions such as while loops and if statements. The sensing instructions allow the user's program to test the location of a sprite or the mouse pointer. In the “operators” category, we find arithmetic, boolean, and string operators that can be combined to form complex expressions. Finally, the “variables” instructions allow the user to create, display and manipulate scalar and list variables.
Given the power of the environment that Scratch provides its user, you can imagine that people are anxious to share their creations. Scratch lets users share them via the Scratch website, but there is also a Java interpreter that allows a user to embed their creation in a web page. I've also heard rumors on the forum that there is a Windows compiler that will turn a Scratch project into a stand-alone executable. In fact, if you go to the Scratch projects web page, you can actually test drive a project before you download it.
I only have one suggestion and one criticism of the Scratch program. For me, the programming area was way too small. I easily filled it and had to scroll around to see the big picture in anything but the most trivial of programs. Finally, it would be really really neat if Scratch could have even a simple networking stack. A networking stack would open up an entire universe of new opportunities for Scratch programing.
Since committing to write this article, I've spent a lot of time playing with Scratch, both with other people's projects, as well as my own. I'm still thinking of fun things to do with it as well as ways to integrate Scratch into our homeschooling curriculum. This is a program that you really need to check out.
Mike Diehl is a freelance Computer Nerd specializing in Linux administration, programing, and VoIP. Mike lives in Albuquerque, NM. with his wife and 3 sons. He can be reached at email@example.com
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems
Free to Linux Journal readers.Register Now!
- Considering Legacy UNIX/Linux Issues
- Cluetrain at Fifteen
- [<Megashare>] Watch Mrs Brown's Boys Movie Online Full Movie HD 2014
- Memory Ordering in Modern Microprocessors, Part I
- Getting Good Vibrations with Linux
- Security Hardening with Ansible
- New Products
- Putlocker!! Watch Begin Again Online 2014 Streaming Full Movie
- RSS Feeds
- Tech Tip: Really Simple HTTP Server with Python