Computer lab sessions during school in the late 90’s were synonymous with one thing – Logo. This environment/programming language, call it what you may, had been the mainstay of computer lectures in nearly all schools across the country. Kids from the 3rd to 6th grade could be found carefully punching out the commands to solve the exercise and watch the ‘turtle’ zoom around doing their bidding. Behind the seemingly benign facade, Logo explored some of the very intricate aspects of functional programming and provided kids with an easy and an interactive way to pick up computer programming.
The only problem with Logo is that it’s too bland, no one let alone kids, likes to stare at a blank screen with a small triangle drawing squiggly lines everywhere. Enter Scratch – a brainchild of the excellent people over at the MIT Media Lab, the same people who came up with the revolutionary augmented reality technology called the Sixth Sense, a couple of years back. Imagine Logo with a colorful new interface, a Lego-like way of building your program from blocks, an online repository where you can share and discover new projects (a la Github) and above all the ability to replace the boring old triangular turtle with any graphic of your choice, and the end result is Scratch. The program and the interface are quite explanatory (the least you can expect from a programming language learning environment for kids). This workshop will cover everything from the setup to some programming fundamentals.
Head over to the Scratch download page and grab the latest version of the application for your operating system. The minimum requirements are Windows 2000 or later, Mac OS X 10.4 or later, Ubuntu Linux 9.04 or later. The installation method will change if you’re running Linux. On Ubuntu, just type in sudo apt-get install scratch in the terminal or look for Scratch in the Software Center. If you’re running Fedora, you can grab an RPM from goo.gl/zXFBX. On other Linux distributions you’ll have to manually build the project from the source code which can be found here goo.gl/BKX0E.
The Scratch team has also released a network installation executable so you can easily install and manage Scratch on multiple computers. Follow the instructions to install Scratch remotely on multiple machines. This can be especially helpful, if you plan to install it in the entire lab.
A Scratch project is built around what is called a sprite. A sprite behaves exactly like the one used in game development. You can change the ‘costume’ of a sprite, you can also change the sound and most importantly you can associate scripts with a sprite which define its actions on the stage.
1. Script blocks palette
The palette contains blocks, which can be dragged into the scripts tab to program the sprite. There are eight types of blocks available – Motion, Looks, Sound, Pen, Control, Sensing, Operators and Variables. You can use any of these blocks to create scripts.
Program blocks for various functions
2. Sprite info area
The sprite info area shows the currently selected sprite’s name, X and Y position of the sprite on the stage, direction and orientation, pen status and lock status. You can play around with these settings to show how the sprite will look when it points in various directions.
3. Scripts tab
You can drop the blocks from the script palette in this area to build your program. You can stack multiple blocks to create a program. Clicking anywhere on the stack will run all the blocks from top to bottom. When you drag a new block into the scripts tab, a white highlight appears which indicates where you can drop the block to create a valid connection with other blocks. You can move around a stack by clicking and dragging the top block. If you drag from the middle of a stack, it’ll take all the blocks below that block including itself. You can add comments to your code by right-clicking in the script area and selecting ‘add comment’. You can attach a comment to the block by dragging it to the top of the block.
4. Costumes Tab
In this tab you can view and edit a sprite’s costume. As mentioned earlier, a sprite can have an unlimited number of costumes. You can add costumes to a sprite in four ways:
• Paint –You can paint a new costume for the sprite in the bundled paint editor. It is much like the Paint tool bundled with Windows without any added functionality.
• Import –You can directly import JPEGs, PNGs or GIFs as they are from your hard disk
• Camera –You can use your webcam to click photographs and use them as a costume.
• Drag and Drop – You can drag and drop an image from your desktop or a website. You can export a selected costume as a new sprite by right-clicking on the desired costume in the costumes tab and selecting ‘turn into a new sprite’.
5. Sounds Tab
You can record or import sound files in this tab which can be played along with your animation. Scratch recognizes MP3, WAV, AIF and AU files.
The stage is the place where all the action takes place. The sprites move and enact the actions specified in the scripts on the stage. The stage is 480 x 360 units in size. It’s divided into a Cartesian grid with the center (0,0) in the middle of the stage. You can find your current position on the stage by checking the status tab at the lower-right corner of the Stage. You can switch sizes using the button on the top right corner. One thing to note, the stage itself is a sprite so double clicking on the stage or selecting the stage in the sprite list will open up its script, background and sounds tab.
7. Sprite List
The sprite list contains the thumbnails of all the sprites inside a project. Double-clicking on a sprite opens its script, costume and sound tab, the selected sprite is highlighted with a blue border. Scratch defaults to a cat’s sprite when you open it, you can add new sprites by using the buttons on top of the sprite list. You can export sprites to a '.spritefile' which can then be used across various projects.
Scratch is billed as an environment/programming language which “makes it easy to create interactive stories, games, and animations”. Albeit a toy language which is used for teaching, it contains nearly all constructs of a modern functional programming languages – variables, conditional statements, loops, operators and events.
The blocks mentioned in the section above which are used to construct the scripts are divided into three sections.
These blocks have indentations on the edges which look like bumps and notches. Multiple such blocks can be snapped together to form a stack. Some blocks have input fields inside them which allow you to modify the menu either by typing it in or selecting one from a dropdown. Some stack blocks are C-shaped which allow you to place other stacks or blocks inside that block.
These blocks have a rounded top and must be placed on top of the stack for them to work. They listen for particular events and when the event is triggered they execute the block/stack attached below them.
These blocks behave like variables and go into the input areas of some of the blocks of the other two types. Reporters with rounded borders will return string or numbers which can used by other blocks, while the reporters with pointed ends return Boolean values i.e. True or False. You’ll usually find them being placed inside blocks with conditions. Click on any reporter to see it’s current value. Some of the reporters will have a checkbox next to them, when you check such reporters a monitor appears on the on the stage which shows the current value of the reporter.
Scratch also allows you to create and manipulate lists. List is a type of variable and can be created from within the variable block palette. When you create a list, a monitor will appear on the stage. It will show all the items in a given list. You can enter items inside a list using a monitor. Scratch can also handle strings and user input. You can find the user input blocks in the Sensing block palette.
Perhaps the most interesting aspect of Scratch is to share your code with the entire world, right from the interface itself. It’s like Github but for mini games and stories. Everyone has the access to everyone's code, you can download anyone's project and start modifying and the same is true vice-versa. Such projects are called remixes. You’re free to view and modify anyone's image on the Scratch website. This will help you learn interesting ways in which Scratch can be used to solve problems and a great way to learn new things about Scratch.
To start sharing your code you’ll have to open an account on the Scratch page. Once done with that you can put in the username and password in the share dialog in the interface, enter an appropriate project title and description and you’re good to go. In case you’re having problems uploading your project (the maximum project size supported is 10MB) you can try compressing the images and sound files from the edit menu in the application.
Also Read: How to start a career as a Game Designer