Your Turn!
Now it’s your turn. Download this document for a recap of the blocks we covered in this lesson and some hands-on exercises for you to explore.
What You Have Learned in This Lesson
Programming with the Pen category
In this lesson, you have learned how to draw the movement of your sprite on the stage using the blocks in the "Pen" category. If you put the pen down, all the sprite’s motions are drawn onto the stage until you put thepen up again. You can delete everything that is drawn on the stage with the clear block. You can set and change the size of the pen.Additionally, you can choose a pen color with different blocks.
Snap!’s pen color is based on the HSB color model. HSB is often used in graphic design programs because its way to generate colors is closer to how we perceive colors and thus it is easier for us to find the values for a specific color.
In the HSB-color model, S and B represent saturation (2) and brightness (3) of a color and they are usually on a scale between 0 and 100.
H stands for hue (1) and is usually set with the angle in a color circle (0-360°).
In Snap!, the hue is instead represented by a color band from 0-99 to have the same scale for all color components.
Combining all three color dimensions lets you generate many different colors.



The three color dimensions are also partly represented in the color picker of the set pen color to block. As mentioned, in Snap! the hue is not based on the angle in a color circle but rather on the position in the color band (0-99). The color band is repeating continuously, meaning 0, 100 or 200 is the same shade of red.

In summary, this is how you can use the three options to set the pen color:

Writing custom blocks in Snap!
In this lesson you also learned how to write your own custom blocks in Snap! with the "Make a block" feature.
This is useful if you want to use parts of your code more than once in your project or even in several projects. Additionally, you can make your code more readable by hiding away the technical details (abstraction). You can also make multi-purpose blocks by generalizing concepts – in this case we generalized the algorithm for a polygon, and were able to create a block that can draw polygons with any number of sides (generalization).
In Snap!, there are three ways to open the block editor to create custom blocks. You can either click the plus sign at the top of the palette in each category or the "Make a block" button at the bottom, or you can right-click the scripting area and select "make a block…" from the context menu.
In the now opened dialog box you first need to specify your block’s features such as category (1), label (2), block type (3), and availability (4) for your block. Click "OK" when you filled out everything in order to access the block editor.

The block editor shows you the so-called block prototype of your block. It’s a hat block with a version of the future block on it.
Attach the script that is supposed to be executed whenever that block runs to the prototype. That script is called the block definition.
Press "OK" to save your block and close the block editor or "Apply" to just save your block and keep the block editor open.
All custom blocks are located at the end of their category.

Like any other block, custom blocks can also have parameters. To add an input slot to a block, click on the + sign on the block prototype where you want the input to be. This opens a dialog box, in which you can specify whether you want to create an input (default selection) or expand the title text. Enter the name of the parameter or label and press "OK" and "Apply" to generate the input.
Your block now has an input slot on the outside and an orange reporter with the name of the input on it in the block header inside the block editor.
This orange reporter stores the value of the input and can be dragged out of the block header to be used inside the block definition.
Clicking "OK" and "Apply" will add an input slot to your block, which is represented by an orange input reporter inside the block editor. Any value you add as input to the block is stored in the orange reporter and can dragged out of the block header to be used inside the block definition.

You can edit custom blocks by right clicking the block and selecting "edit…" from the context menu.
One of the main reasons of writing your own blocks is generalization and abstraction - hiding what’s really going on behind a more convenient interface. If you want to know more about abstraction and where you can find it in our everyday life, check out Prof Brian Harvey’s abstraction lecture from UC Berkeley’s "the Beauty and Joy of Computing" course: https://www.youtube.com/watch?v=ok_KcxqVrOk
Reusing scripts across different projects
You can export scripts to use them in other projects. This will also export all custom blocks including their definitions and dependencies.
To export a script, you can right click it and select "export…" from its context menu. This will download an XML file to the downloads folder of your browser.

To import the script to another Snap! project, you can drag and drop it from your file browser onto that browser tab. Alternatively, you can select the "Import…" option from the file menu to open your computer or tablet’s file browser. Navigate to the xml file of the script and select "OK" to load it into the current browser tab.