Sunday, January 30, 2011

Build Your Own Blocks

Build Your Own Blocks (BYOB) is an extension to the visual drag and drop programming of Scratch. It adds custom blocks, recursion, first class lists and procedures to the original.

The developer is Jens Mönig with design input and documentation from logo legend Brian Harvey.

There is a make a block shape in the Variables section. When you click on it an easy to use block editor comes up. First up, I made a block that draws squares, then followed up with a hex block and a star block. Here they are:

I am following a sequence suggested by Jens and Brian in their paper, Bringing 'No Ceiling' to Scratch: Can one language serve kids and computer scientists?

The next step is to draw a V shape with a randomly chosen decoration at each end. In a text based logo language this would look like:

to v
left 45 forward 50
run pick [square hex star]
back 50 right 90 forward 50
run pick [square hex star]
back 50 left 45
end

The tricky bit here is how to implement the line: run pick [square hex star] visually. Initially, I couldn't figure that out but my friend Tony Forster helped me with it:


And here is the whole v procedure, in visual block form:

This procedure draw shapes like this, (running it 3 times with different starting positions):

The next step illustrates how to do recursion in BYOB! Recursion means that a procedure calls itself. Here it is:



There are a couple of places where vee might randomly call vee causing the procedure to loop back on itself. Since it is random (item any) then the result are varied and unpredictable. Here are a couple of the more complex results:

As well as the paper by Jens and Brian make sure you read the manual which comes with the download, too.