Exercise - Review of Snap!

Snap! is a browser-based graphical programming language used for all the robot programming activities in this workshop. Ideally students will already be familiar with Snap! (see Prerequisites) but the following is a guide to quickly learning enough of the system to get started.

Basic Concepts

Snap! is a drag-and-drop block-based language created at UC Berkeley as an improvement on Scratch. Programs are constructed by dragging blocks representing computational operations into stacks. The blocks have exterior and interior shapes which indicate the kinds of functions they perform. The system will only allow blocks to fit together which have compatible properties. E.g. a block with a slot expecting a true or false input value has a hexagonal shape; blocks which produce a true or false value have a hexagonal exterior and will be allowed to fit into the slot. Note that doesn’t mean the program will work, just that all programs which can be drawn are syntactically correct and can be evaluated.

The usual application of Snap! is writing interactive graphical programs which draw sprite and pen graphics in a browser canvas and make sounds. The Snap! support for the Finch robots adds additional blocks which communicate with the robot hardware. Most of the drawing and sound operators will not be used in this course since we will focus on robot performance.

The important improvements of Snap! over Scratch can be summarized as follows:

  1. Support for cloud storage of sketches. The ScratchX system used with the Finch does not have access to the community cloud system, so it is difficult to share sketches. Note, however, that Snap! does not have a community portal, just a cloud server, but users may pass out their own links to sketches they make public.
  2. Support for recursion in user-defined blocks.
  3. First-class data lists. Together with recursion, this opens the door to many programming techniques, including structured data manipulation and object-oriented design.
  4. Implementation in Javascript instead of Flash (more broadly compatible with new devices, more future-proof).

Online Resources

The course guide includes the following Snap! resources:

  1. All sketches associated with this course are described in the code notes.
  2. Quick reference guide to the standard Snap! and Finch blocks
  3. Reference guide to the course Snap! library

The following general resources are available from BirdBrain and UC Berkeley:

  1. BirdBrain Finch and Snap guide
  2. BirdBrain Snap! tutorial
  3. BirdBrain Snap! library (direct link to interactive system)
  4. Snap! interactive system (i.e. without Finch) (direct link to interactive system)
  5. Snap! official reference manual
  6. Snap! source code

Agenda for Review

Your instructor will guide you through the following topics and terminology:

  1. Starting Snap!
    1. For Snap! alone: run Snap!
    2. With the Finch, start the Finch Connection App first.
  2. Saving your sketches.
    1. Creating a cloud account from within Snap! so you can work on sketches from any computer.
    2. Saving both locally and on the cloud.
    3. Setting cloud sketches to be public.
    4. Note: Finch-based sketches can still be loaded and run even if no robot is attached, although any robot-related output operations will have no effect and sensor operations will return default values. This can be useful for offline testing.
  3. Basic block types and terminology:
    1. Hat blocks.
    2. Command blocks.
    3. Reporter blocks (oval).
    4. Predicate blocks (hexagon).
    5. C-shaped blocks.
  4. Control flow through blocks.
  5. Atomic data types:
    1. Numbers.
    2. Booleans.
    3. Strings.
  6. Finch command and reporter blocks.
    1. Robot output commands.
    2. Sensor reporters.
  7. Controlling timing and delay.
  8. Global variables.
  9. Script variables.
  10. Lists.
  11. Threading and concurrent execution.
  12. Defining new blocks.
    1. Arguments.
    2. Return values.
    3. Recursion.
  13. Using block libraries.
  14. Reading code defined within Snap!.