Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Snap! user discussion
- _nix
-
1000+ posts
Snap! user discussion
Perhaps you're looking for the “is a” block, in the Operators category? Are there hexagonal predicate blocks for determining if a variable is a list or a scalar in Snap!? I need to create a data structure out of linked lists and then parse it and I need to know when I get to the leaves of the tree.

- s_federici
-
500+ posts
Snap! user discussion
I tested the new vector editor in the /dev version and I couldn't draw a circle (that is just the border with a transparent fill). Is there an easy way to do it that my quick test didn't discover?
- Jens
-
100+ posts
Snap! user discussion
Hi Stefano, the new vector editor is not yet optimal, but we'll get there. To draw an outline right now: Set the secondary color to the one you want by clicking on it, then set the primary color to transparent but shift-clicking on the transparent part of the color picker, then select the shape and start drawing. The trick is that shift-click selects primary / secondary color.
- nigeldodd
-
14 posts
Snap! user discussion
Perhaps you're looking for the “is a” block, in the Operators category? Are there hexagonal predicate blocks for determining if a variable is a list or a scalar in Snap!? I need to create a data structure out of linked lists and then parse it and I need to know when I get to the leaves of the tree.
I did look, but my eyes must have glazed past it. Yes, thank you, this is precisely what I want.
- comp09
-
1000+ posts
Snap! user discussion
fileWoo hoo! Firefox FTW! but it does work in Firefox.
Yes, it's clearly a security thing. I'm going to defer to an expert… Michael? Bernat? Jens?

You can work around this by putting the files on an HTTP server instead of loading them from the filesystem directly.
- bharvey
-
1000+ posts
Snap! user discussion
https://snap.berkeley.edu/draftManual.pdf page 10 there is a cludge where every note has *binary-tree* as its first item and of course you can test that, but is there a more elegant way of testing?Your problem is solved, but I wanted to comment on this part of your statement of it. The point of the explicit type tag is not to distinguish vector from scalar; ITEM 1 OF will fail if its input is a number. The point is to be able to distinguish I note that in abstract types: binary tree vs. heap vs. hash table, for example, all of which would be represented as lists. So it's not a kludge.

- Jens
-
100+ posts
Snap! user discussion
RE: Selecting the secondary color in the Vector Paint Editor
Hi Stefano (and all), I made it so right-clicking on the color picker also selects the secondary color (alternatively to holding down the shift-key). I hope that for now that makes it a little bit easier to discover how to set both colors, since the color monitors also also arranged left-to-right. It's still far from optimal but hopefully slightly better for the upcoming release.
Hi Stefano (and all), I made it so right-clicking on the color picker also selects the secondary color (alternatively to holding down the shift-key). I hope that for now that makes it a little bit easier to discover how to set both colors, since the color monitors also also arranged left-to-right. It's still far from optimal but hopefully slightly better for the upcoming release.
- s_federici
-
500+ posts
Snap! user discussion
Thanks Jens, it worked well. Shift-clicking is for secondary (that is, border) color, right? Hi Stefano, the new vector editor is not yet optimal, but we'll get there. To draw an outline right now: Set the secondary color to the one you want by clicking on it, then set the primary color to transparent but shift-clicking on the transparent part of the color picker, then select the shape and start drawing. The trick is that shift-click selects primary / secondary color.
- s_federici
-
500+ posts
Snap! user discussion
Thanks RE: Selecting the secondary color in the Vector Paint Editor
Hi Stefano (and all), I made it so right-clicking on the color picker also selects the secondary color (alternatively to holding down the shift-key). I hope that for now that makes it a little bit easier to discover how to set both colors, since the color monitors also also arranged left-to-right. It's still far from optimal but hopefully slightly better for the upcoming release.
- DarDoro
-
27 posts
Snap! user discussion
fileWoo hoo! Firefox FTW! but it does work in Firefox.
Yes, it's clearly a security thing. I'm going to defer to an expert… Michael? Bernat? Jens?/ XHR is not allowed in Chrome for security reasons.
You can work around this by putting the files on an HTTP server instead of loading them from the filesystem directly.
This options may be helpful for Chrome, but with serious security implications:
-–allow-file-access-from-files –disable-web-security –user-data-dir=…
- cycomachead
-
100+ posts
Snap! user discussion
Woo hoo! Firefox FTW! but it does work in Firefox.
Yes, it's clearly a security thing. I'm going to defer to an expert… Michael? Bernat? Jens?
Yes, it's a security thing.
Two things:
* only a specified set of domains can access the cloud - anything else will fail.
* when doing local work you can access more stuff by using a local web server.
The current list of domains is here:
https://github.com/bromagosa/snapCloud/blob/master/app.lua#L56
If you have Python installed, it's pretty easy to setup a local server, and if you use port 8080 the cloud should function.
This page has some instructions. (Scroll to the end of the command to run if you want to just use the command line).
https://docs.python.org/2/library/simplehttpserver.html
If you don't want to mess with Python, you can use something like XAMP to serve files, or a lot of other apps to probably.
- coordinator21
-
1 post
Snap! user discussion
Hello,
Please I would like to know if you released any offline version for Snap to be installed and used on Windows Tablets?
Thanks
Please I would like to know if you released any offline version for Snap to be installed and used on Windows Tablets?
Thanks
- bharvey
-
1000+ posts
Snap! user discussion
Not specifically for tablets. We have a version for Windows Please I would like to know if you released any offline version for Snap to be installed and used on Windows Tablets?computers that might work; I don't have anything to try it on. Here's what to do:
1. Open Snap!.
2. Without loading a project, go to the file menu and choose “export project.”
3. Now go to http://snapp.citilab.eu/.
4. Click on “Choose file” and select the empty project you just saved in step 2.
5. For “Target OS” choose “Windows 64 bit” or “Windows 32 bit” as appropriate.
6. Important: Click the “code accessible” box.
7. Now click “Make my app” and you should have a runnable standalone version.
- hjcpps
-
40 posts
Snap! user discussion
Congrats on the 4.2 release!
Thank you for the clarity on cloud access.
Maybe. I do see the security risk of allowing unprompted access to local files. And I have found one instance when Firefox consumes one gigabyte or more of memory when opening a Snap! project.Woo hoo! Firefox FTW! but it does work in Firefox.
I had tried - -allow-file-access-from-files, with no effect. It turns out that Chrome now requires that flag to be used with - -user-data-dir=__ . Together they did resolve the error reported in the Chrome console, but Snap! continued to report the same error. I couldn't immediately see a reason for this. This options may be helpful for Chrome…
Even if I can resolve this, setting up a local server may eliminate other or future issues. I will probably go with the Python 3.x http.server Two things:
* only a specified set of domains can access the cloud - anything else will fail.
* when doing local work you can access more stuff by using a local web server.
Thank you for the clarity on cloud access.
- bharvey
-
1000+ posts
Snap! user discussion
Snap! v4.2 is out! (from Jens)
Folks,
I've just released and installed the latest not-so-minor Snap! version 4.2 chock-full of exciting new features such as recovering projects, a vector paint editor, a JIT compiler, new blocks and options etc.
The brand-new version is already up-and-running at:
https://snap.berkeley.edu/run
It is fully compatible with the previous stable one and also fixes a bunch of bugs and glitches. It's been well tested over a longer period of time, so I don't expect any showstopper issues. Also you won't have to (tell your students to) to flush their browser caches, everything should work automatically, just better
In case you do encounter a problem the previous stable version (4.1.2.7) is still available at:
https://snap.berkeley.edu/snapsource/stable
and will remain so until the next release.
As usual, the sources are all up at Github:
https://github.com/jmoenig/Snap--Build-Your-Own-Blocks/releases/tag/4.2
I was going to write up some more detailed release notes, and promise to do so in the next days / weeks (haha), but, alas, there's urgent other stuff on my desk, so here goes the readers' digest version for now:
v4.2 New Features
Notable Changes
Notable Fixes
Translation Updates
Anyway, since I've already made screenshots of new stuff some brief pics of explanation:
Recovering Projects
“The SnapCloud lost all my work” is the contemporary version of “the dog ate my homework.” We haven't been able to confirm any actual data loss on the cloud, but people claim they sometimes – extremely seldom – overwrite an existing project with a same-named empty or older one (ignoring all the warnings etc. etc.). In order to mitigate personal tragedies arising out of flunking the AP course and having to go to a sub-optimal college we're now storing up to 3 versions per project in the cloud:
1) The current version,
2) the version saved before the current one
3) yesterday's last saved version
The rules are slightly more subtle, but the idea is that if you notice you've accidentally messed up the project you're working on you can always go back to the last version, or to yesterday's last one.
The project dialog has a new “recover” button:

It opens a versions dialog for the selected project, letting you open a previous version:

You don't need to worry about creating versions, Snap! does that for you.
But hey, we're still very much encouraging you to also export your project to your local computer hard drive (or flash, or whatever your choice of persistent memory) from time to time.
Vector Paint Editor
The normal paint editor for creating costumes now has an additional button letting you switch to the vector version:

This is a very simple and still somewhat rough sketching app that lets you draw costumes composed of individual shapes:

You can then select one or multiple shapes and manipulate it (also copy, paste, delete etc.), you get the idea. Note that the editor has two colors for many shapes. You can select the primary with the left mouse button, the secondary one with the right mouse button. There are more details for the long version of the release notes ;-)
Oh, did I mention that vector costumes are nice because the scale seamlessly?
Keeping Robots from Tripping off the Table
Hardware folks like Tom and Steve and AI-hackers like Ken Kahn have been asking us for ages to expose the Stop-Button gesture as an event so they can (let kids) write this script:

The latest release enables this. the event gets fired whenever the user presses the red stop button, holds down the esc key in edit mode, or when a script executes the “stop all” block. Since starting one or more scripts when the user wants everything to be stopped can easily lead to a sorcerer's apprentice situation we're making sure that such “on stop” scripts are only running for a single frame before every process is terminated for good. However, many times you'll need to not just do a single action such as stopping only motor:

but you'll want to enumerate all of them, or a list of hardware pins:

Since this would take more than a single frame we've made it so that the “on stop” scripts always run atomically, i.e. in a single step. This is the same as “WARP-ing” them, except you don't need to remember to explicitly use the WARP block on them.
Okay, okay, now you want to know what happens if you use a FOREVER block, infinite recursion or tail-recursive broadcasts, right? These cases should be fine, because we're forcing atomic scripts to yield about every half-second, and then we're killing them if the user did want every process to be stopped.
Crunching “Bigger Data”
We've been exploring various ways to make working with “bigger” data more interesting, and one of our favorite themes has been working with the pixels of a photo from the webcam or the samples of a recorded sound. While Snap! usually is fast enough to produce results reasonably quick we want to work with bigger data sets and also make things like graphic effects more interactive still. To accomplish this we've been experimenting with automatically compiling parts of those scripts instead of interpreting them inside Snap. While compiling scripts leads to a significant speed-up it also introduces the possibility of crashing Snap! or making it altogether unresponsive in case of a semantic error. Therefore this is something to use with caution while we're conducting more research into how to find the right balance between raw power and friendly scaffolding.
The new version has a new library for “Bigger Data”:

The idea is that you write your projects using the normal higher-order function blocks found in the TOOLS library (MAP, KEEP, COMBINE) and debug them so you know the scripts are working correctly. Then you import the “Bigger Data” library and relabel the relevant blocks with their flash-symbol counterparts.
For example, here's a script that posturizes a photo. I want to make it so moving the mouse over the picture changes the posturization threshold according to the mouse's x-position. Constantly recomputing this complex operations is rather slow in Snap!. Therefore I can relabel the normal version of MAP to the one displaying the flash symbol:


The “flash” version uses JIT compilation for the embedded function that manipulates each pixel to make it very fast, so you can make interactive graphic effects such as this one:

Here's the final script using the “Bigger Data” library:

More details to follow soon… :-)
New Blocks and Options
There's a new library letting you programmatically declare global and sprite-local variables:

The SET block now features a submenu allowing you to access the target sprite's attributes. This is useful when doing OOP:

The “Pixels” library has a new additional reporter in the sensing category letting you take a snap shot with the webcam:

Likewise the Audio Comp Library has a similar reporter letting you record a sound snippet using the microphone:

The “Pixel” library now also lets you access the names of costumes:

And the “letter of” reporter now has a drop-down menu with the same options that the “item of list” block has (thanks, Dan, for the suggestion):

Already Snap! lets you refer to coordinates using two-item lists:

The new version also introduces the “center” selector, because it's frequently used in beginners' projects:

I've also finally gotten around to fixing the layout of variadic command-type slots, so you can now make blocks like this one:

to write scripts like this:

(here's how you could do it, btw):

Okay, so much for now. There is urgent stuff on my desk, sigh…
Please let me know if you encounter any issues. Also, feel free to forward this email to anybody I've forgotten to include who should know about this.
Enjoy!
Jens
Folks,
I've just released and installed the latest not-so-minor Snap! version 4.2 chock-full of exciting new features such as recovering projects, a vector paint editor, a JIT compiler, new blocks and options etc.
The brand-new version is already up-and-running at:
https://snap.berkeley.edu/run
It is fully compatible with the previous stable one and also fixes a bunch of bugs and glitches. It's been well tested over a longer period of time, so I don't expect any showstopper issues. Also you won't have to (tell your students to) to flush their browser caches, everything should work automatically, just better

In case you do encounter a problem the previous stable version (4.1.2.7) is still available at:
https://snap.berkeley.edu/snapsource/stable
and will remain so until the next release.
As usual, the sources are all up at Github:
https://github.com/jmoenig/Snap--Build-Your-Own-Blocks/releases/tag/4.2
I was going to write up some more detailed release notes, and promise to do so in the next days / weeks (haha), but, alas, there's urgent other stuff on my desk, so here goes the readers' digest version for now:
v4.2 New Features
- “recover project” feature, (cloud backups), thanks, Bernat Romagosa!
- vector paint editor, thanks, Carles Paredes and Bernat Romagosa!
- “When I am stopped” event option, runs one atomic frame before terminating, use-case: stop robots when a user hits the stop button
- experimental JIT compiler for atomic HOFs, used in new “Bigger Data” library
- new library for programmatically creating variables, thanks, Brian Harvey!
- added options for sprite attributes to the SET block
- new “webcam snap” reporter in the “Pixels” library
- new “record” reporter in the “Audio Comp” library
- added “name” selector to the “Pixels” library
- added drop-down menu to “letter _ of _ ”, thanks, Dan, adjusted all translations (thanks, Joan!)
Notable Changes
- hidden sprites can no longer be collision detected (but can test for other sprites)
- new sprites created by pressing the arrow button no point in random directions (unless you hold down the shift-key)
- new “center” option for location blocks (GO TO, POINT TOWARDS, DISTANCE TO and DIRECTION TO)
- disabled keyboard shortcuts for green-flag (cmd-enter) and stop (esc) in presentation mode
Notable Fixes
- rearranging and scrolling sound icons
- rendering and layout of variadic C-shaped input slots
- when collapsing ring-typed multi-arg slots only filled rings are preserved
- support for numerical custom block input names
- no more “leftover” clones when pressing the stop button or executing the STOP block
Translation Updates
- German, thanks, Jadga!
- Portuguese, thanks, Manuel!
- Catalan, thanks, Joan!
Anyway, since I've already made screenshots of new stuff some brief pics of explanation:
Recovering Projects
“The SnapCloud lost all my work” is the contemporary version of “the dog ate my homework.” We haven't been able to confirm any actual data loss on the cloud, but people claim they sometimes – extremely seldom – overwrite an existing project with a same-named empty or older one (ignoring all the warnings etc. etc.). In order to mitigate personal tragedies arising out of flunking the AP course and having to go to a sub-optimal college we're now storing up to 3 versions per project in the cloud:
1) The current version,
2) the version saved before the current one
3) yesterday's last saved version
The rules are slightly more subtle, but the idea is that if you notice you've accidentally messed up the project you're working on you can always go back to the last version, or to yesterday's last one.
The project dialog has a new “recover” button:

It opens a versions dialog for the selected project, letting you open a previous version:

You don't need to worry about creating versions, Snap! does that for you.
But hey, we're still very much encouraging you to also export your project to your local computer hard drive (or flash, or whatever your choice of persistent memory) from time to time.
Vector Paint Editor
The normal paint editor for creating costumes now has an additional button letting you switch to the vector version:

This is a very simple and still somewhat rough sketching app that lets you draw costumes composed of individual shapes:

You can then select one or multiple shapes and manipulate it (also copy, paste, delete etc.), you get the idea. Note that the editor has two colors for many shapes. You can select the primary with the left mouse button, the secondary one with the right mouse button. There are more details for the long version of the release notes ;-)
Oh, did I mention that vector costumes are nice because the scale seamlessly?
Keeping Robots from Tripping off the Table
Hardware folks like Tom and Steve and AI-hackers like Ken Kahn have been asking us for ages to expose the Stop-Button gesture as an event so they can (let kids) write this script:

The latest release enables this. the event gets fired whenever the user presses the red stop button, holds down the esc key in edit mode, or when a script executes the “stop all” block. Since starting one or more scripts when the user wants everything to be stopped can easily lead to a sorcerer's apprentice situation we're making sure that such “on stop” scripts are only running for a single frame before every process is terminated for good. However, many times you'll need to not just do a single action such as stopping only motor:

but you'll want to enumerate all of them, or a list of hardware pins:

Since this would take more than a single frame we've made it so that the “on stop” scripts always run atomically, i.e. in a single step. This is the same as “WARP-ing” them, except you don't need to remember to explicitly use the WARP block on them.
Okay, okay, now you want to know what happens if you use a FOREVER block, infinite recursion or tail-recursive broadcasts, right? These cases should be fine, because we're forcing atomic scripts to yield about every half-second, and then we're killing them if the user did want every process to be stopped.
Crunching “Bigger Data”
We've been exploring various ways to make working with “bigger” data more interesting, and one of our favorite themes has been working with the pixels of a photo from the webcam or the samples of a recorded sound. While Snap! usually is fast enough to produce results reasonably quick we want to work with bigger data sets and also make things like graphic effects more interactive still. To accomplish this we've been experimenting with automatically compiling parts of those scripts instead of interpreting them inside Snap. While compiling scripts leads to a significant speed-up it also introduces the possibility of crashing Snap! or making it altogether unresponsive in case of a semantic error. Therefore this is something to use with caution while we're conducting more research into how to find the right balance between raw power and friendly scaffolding.
The new version has a new library for “Bigger Data”:

The idea is that you write your projects using the normal higher-order function blocks found in the TOOLS library (MAP, KEEP, COMBINE) and debug them so you know the scripts are working correctly. Then you import the “Bigger Data” library and relabel the relevant blocks with their flash-symbol counterparts.
For example, here's a script that posturizes a photo. I want to make it so moving the mouse over the picture changes the posturization threshold according to the mouse's x-position. Constantly recomputing this complex operations is rather slow in Snap!. Therefore I can relabel the normal version of MAP to the one displaying the flash symbol:


The “flash” version uses JIT compilation for the embedded function that manipulates each pixel to make it very fast, so you can make interactive graphic effects such as this one:

Here's the final script using the “Bigger Data” library:

More details to follow soon… :-)
New Blocks and Options
There's a new library letting you programmatically declare global and sprite-local variables:

The SET block now features a submenu allowing you to access the target sprite's attributes. This is useful when doing OOP:

The “Pixels” library has a new additional reporter in the sensing category letting you take a snap shot with the webcam:

Likewise the Audio Comp Library has a similar reporter letting you record a sound snippet using the microphone:

The “Pixel” library now also lets you access the names of costumes:

And the “letter of” reporter now has a drop-down menu with the same options that the “item of list” block has (thanks, Dan, for the suggestion):

Already Snap! lets you refer to coordinates using two-item lists:

The new version also introduces the “center” selector, because it's frequently used in beginners' projects:



I've also finally gotten around to fixing the layout of variadic command-type slots, so you can now make blocks like this one:

to write scripts like this:

(here's how you could do it, btw):

Okay, so much for now. There is urgent stuff on my desk, sigh…
Please let me know if you encounter any issues. Also, feel free to forward this email to anybody I've forgotten to include who should know about this.
Enjoy!
Jens
Last edited by bharvey (June 23, 2018 05:32:56)
- s_federici
-
500+ posts
Snap! user discussion
Snap! v4.2 is out!I didn't test them yet, but I was really waiting for the new vector editor, the variable creation library and the JIT compiler!
These features will make my work on my mod BloP much easier (letting users create variables in their custom block-language) and estetically nicer (having the elements of their new language zoom/unzoom gracefully). And, I hope, the final language will be quicker with the JIT compiler!
I'm going to test all this during the next weeks. I really hope to let you now that they work as I expect!
- xly
-
100+ posts
Snap! user discussion
@Jens
I use extensively Fmap and Pixel library with JIT compiler.set On for my project modeling Deep Learning Convolution (I shall publish it soon)
I'm surprised that new “flash” Map cuts processing time by 2 compared to Fmap although it is already written in JS !!!
Setting Fmap to“flash” does not change computing time, and new Map stays twice better.
It seems that it is no more necessary to set On JIT compiler.
Congratulations Jens & Brian !
xly
I use extensively Fmap and Pixel library with JIT compiler.set On for my project modeling Deep Learning Convolution (I shall publish it soon)
I'm surprised that new “flash” Map cuts processing time by 2 compared to Fmap although it is already written in JS !!!
Setting Fmap to“flash” does not change computing time, and new Map stays twice better.
It seems that it is no more necessary to set On JIT compiler.
Congratulations Jens & Brian !
xly
- bharvey
-
1000+ posts
Snap! user discussion
All Jens. Well, I guess I get part of the credit for saving backups, even though I didn't write the code; I just hustled the money to pay Bernat for a month so I could tell him what to do first. Congratulations Jens & Brian !

- Jens
-
100+ posts
Snap! user discussion
Thanks, Xavier! Of course, right after the release I discovered a bug in my JIT compiler, but all in all I'm already really pleased with it. Hey, I'm really curious about your deep-learning project! I don't know anything about neural networks and can't wait to learn all about them.
- Hardmath123
-
1000+ posts
Snap! user discussion
Are there any tools to use Snap! to control CNCs? I want to laser-cut a rather complicated shape, and because my CS training comes from Brian, the most natural way for me to describe the shape is with a recursive turtle script. It would be really cool if there was a Snap! library that provided all the motion blocks, but I could right-click script and say “export to gcode…”
Shape: https://imgur.com/a/EhVHG4T
Shape: https://imgur.com/a/EhVHG4T