The Grownup Guide to Bitsbox

First Things First Info for Educators

Dig, Bunny, Dig!

An example app for kids to code with a digging rabbit

This app sends a rabbit burrowing all over the screen. Her movements are random, and the pattern she draws with her tunnels is different every time.

1 fill('buried')

Line 1 puts a background image of an underground world on the screen.

2 r = stamp('rabbit3',150)

Line 2 stamps a rabbit on the screen and assigns it the name "r".

Line 3 is left blank to create visual spacing in the code.

4 function loop() {

Line 4 creates a new block of code called loop() which tells the app to repeat everything inside it 20 times per second, forever.

5 stamp('dig', r.x, r.y )

Line 5 stamps a black circle at the same screen location as the rabbit. Put together, hundreds of black circles combine to look like a tunnel.

6 r.move(RIGHT,20)

Line 6 tells "r" (which is the rabbit) to move.

7 r.wrap()

Line 7 tells "r" (which is the rabbit) to "wrap" around if it gets to the edge of the screen. If it goes off the top, it appears at the bottom, and so on.

8 r.front()

Line 8 tells "r" (which is the rabbit) to appear on top of the stamp 'dig'.

9 if (random(50) == 1) {

Line 9 begins an if statement. If the expression between the parentheses is true, the code on line 10 should run. If the expression is false, the code doesn't run at all.

10 r.rotate(random(360),1000)

Line 10 tells "r" (which is the rabbit) to rotate by a random amount, and to take 1 second to do it.

11 }

Line 11 uses a curly bracket } to indicate that this is the end of the if statement which started on line 9.

12 }

Line 12 uses a curly bracket } to indicate that this is the end of the loop() function which started on line 4.