On this page, you will create many different pictures (like the ones above) by creating a single block with an input slot: . Input slots allow one block to do many related jobs.
The scripts are essentially all the same; only the input values change. Instead of having many separate scripts, you can make one more general script that will draw all such designs. Your pinwheel
block will need an input to specify how many branches you want, just as the
go to
block has inputs to specify x and y values .
Oh, about the orange box on 1.3.3, I think the comment on the hat block is okay, but the comment on the turn is exactly the sort of thing I wouldn't do. In fact I might make a point of saying that when you're /teaching/ someone, you (we) put in comments that you wouldn't use if you were just programming for yourself.
But the hat block comment in the movie isn't very good documentation. It should say "Draws a REGULAR five-sided polygon, with SIDE LENGTH set by the input." (Not really capitalized; I just did that to emphasize to you what's missing.)
Really it's hard to give an example of useful commenting that doesn't look stupid unless you have a big project. Then, for example, when some global variable is used without being set, you might want to attach a comment "FOO is set in procedure BAR that's called in the initialization."
Adding comments to your code helps you remember what your code does, helps other people reading your code to understand it, and can help you avoid bugs by increasing the clarity of your program. This animation shows how to add comments to your Snap! code by right-clicking (or control-clicking) in the Scripts area and choosing "add comment."
Notice that a comment attached to the hat block in the Block Editor becomes the help message for a custom block.
pinwheel
block with an input for the number of branches. Instructions are below and you can also watch the process in the video that follows the instructions.
pinwheel, branches:
pinwheel
, click the + after "branches:" and type number of branches as the name of your input variable.pinwheel
block.We use the word "input" for two different but related things:
The AP CSP framework uses the word "parameter" for both.
pinwheel
block and set pen color
. Create your own art.