dark mode light mode Search Menu
Search

Snap!: A More Powerful Scratch

Stephen Chin on Flickr

Scratch is the biggest blocks-based programming language out there. But it’s not the only one! Today we’ll take a look at a really cool and extremely powerful blocks based language called Snap!. (The exclamation mark is actually a part of the name, but I am also excited about this.)

Snap! looks a lot like Scratch:

Scratch is the biggest blocks-based programming language out there. But it’s not the only one! Today we’ll take a look at a really cool and extremely powerful blocks based language called Snap!. (The exclamation mark is actually a part of the name, but I am also excited about this.)

Snap! looks a lot like Scratch: but under the hood it’s actually pretty different. To show that, we’re going to do a version of the factorial function we showed in our article on recursion also in this issue.

If you remember, a factorial is a mathematical formula shown with an exclamation mark. The factorial 3! is calculated by multiplying all whole numbers between 3 and the number 1: 1 * 2 * 3 = 6. Therefore, 6 is the value of the factorial 3!.

And we can easily compare that to our Python code from the recursion article

def fact(n):
    if n > 1:
    return n*(fact(n-1))
    else:
    return 1

Neat! You can see that these are almost exactly alike, except that in Snap! the way you get a value out of the function is with the report block instead of return like in Python.

If you’re an experienced Scratcher and you’re thinking “hey, there’s no ‘report’ block in Scratch?” you’d be right! In Scratch, only the built-in blocks can return values, like the blocks under operators. How would you write the factorial in Scratch? Well, here’s an example from the official Scratch wiki!

It’s doable but involves creating a list and having extra steps.
Okay, well what else is different in Snap!?

First, you can group sprites together yet have them move independently. Here’s a little example involving a cartoon tank with turret.

As we show in the screenshots below, we’ve made the turret a “child” of the tank body so that when the tank moves forward with the w key both the tank and turret sprites move forward, when the tank turns with the a and d keys then the turret turns as well, but when the turret turns with the left and right keys the tank doesn’t move.

Our combined tank sprite, after dragging the turret in the list of sprites onto the tank body in the stage. Note: you cannot drag the turret sprite onto the tank body in the list of sprites beneath the stage.

Can you do this in Scratch? Well, like the factorial example the answer is “yes, but it’s harder”. That’s essentially my pitch about Snap! in general: it takes things you can do in Scratch but are really inconvenient and makes them a lot easier to do.

Here’s one last really little example of something convenient in Snap! but awkward in Scratch: for-loops! For-loops are how you do something repeatedly, but count how many times you’ve done the thing so far. Most programming languages have them but in Scratch you have to do something like

Meanwhile in Snap! you can instead just do this:

and you don’t even need to make a seperate variable as the loop counter! That’s only a little bit of savings if you have one for-loop, but if you’re writing physics-heavy code that needs multiple for-loops having to create variables for each is a real pain.

Lastly, here’s a simple example of the fractal Koch’s curve which is made just a little simpler by using variables that only exist inside a single script. In most programming languages these are called local variables.

This is also my promised example from our recursion article that I said you’d find here. Try making this yourself and running it! It’s pretty neat.

Now is Snap! nothing but an improvement over Scratch? Well, not really. It’s a little rougher around the edges. For example, if you’re wondering how to share your project you might be surprised to learn that you need to go under File then Open under the main menu and then select share. Oh yes, you need to “open” your project even if it’s open! There are other small things like this: quirks and inconveniences. But, in the end I think Snap! has a lot of cool features, the bulk of which could fill a college computer science class, and is a great next step beyond Scratch.

 

Learn More

The Snap! Manual

https://snap.berkeley.edu/snapsource/help/SnapManual.pdf

Racket/Scheme text-based programming language that inspired Snap!

https://racket-lang.org/

Algorithmically creating embroidery

https://www.turtlestitch.org/

Factorials

https://factorialhr.com/number-function-factorial

Koch’s curve: snowflake

https://en.wikipedia.org/wiki/Koch_snowflake

Koch Snowflake

http://mathworld.wolfram.com/KochSnowflake.html

Factorials

https://www.mathsisfun.com/numbers/factorial.html

Build your own blocks

https://snap.berkeley.edu/

SNAP!

https://en.scratch-wiki.info/wiki/Snap!_(programming_language)

Factorial examples

https://www.shmoop.com/basic-statistics-probability/factorials-examples.html

Factorial video

https://video.search.yahoo.com/yhs/search?fr=yhs-Lkry-SF01&hsimp=yhs-SF01&hspart=Lkry&p=factorials+for+kids#id=1&vid=f5d3b35c779a7328d3e592961fd4b4d9&action=click

Blocks-based coding

https://en.scratch-wiki.info/wiki/Block-Based_Coding

Fun Facts about factorials

https://theedge.com.hk/fun-facts-about-factorials/