2015-06-10

Learning Scratch (2)

My last blog entry, I briefly talk about what is Scratch. There are ``events'' and that is the trigger of the program. In this article, I would like to talk about one of my students who made a character animation program by Scratch.

Scratch provides key events. When I push the right arrow key, then ``right arrow key push event'' is triggered. When that event happened, I add 10 to the x coordinate of the cat. This means, when the right arrow button pushed, the cat move to the right for 10 steps. If I add more programs like the up arrow moves the cat to upper direction, I can control the cat position by the arrow keys. This is a cat control program.

Today, my student used a dragon. He wrote the same program with the cat. Then, the cat and the dragon move exactly the same way. Of course they should. A current computer is very fast, very precise, and very stupid. It does only what the developer wrote. My student asked me, how he can make the dragon faster. I answered, increase the moving step. Currently one key push moves the dragon ten unit steps. A speed is a moving distance in a certain time. If the step was increased to twenty from ten, the speed of the dragon becomes twice. While after, when I came back to him, he duplicated the key events. Interesting.

His method is the following: when the right arrow push event was triggered, two programs started in parallel. One program change the dragon's x coordinate plus 10, and another program does the same. In the end, the dragon's x coordinate increased by twenty. It seems the Scratch environment takes care the parallel change (i.e., locking), so this program works correctly. When he wanted to move the dragon three times faster than the cat, he copied the program again. What an interesting idea he had! Out of the blue, I recalled one scene of a cartoon, JoJo's Bizarre Adventure. (If you don't know it, please ignore the rest of the paragraph.) It's a scene that Jotaro floated in the air using his stand. He can move in the air by pushed his stand. My idea was increase the speed of the stand, but my student idea was increase the number of stands. Two stands can push twice faster, three stands can push three times faster.

But this student's idea can only make whole number times speed. He cannot make the dragon 1.5 times faster than the cat. Of course one program can push the dragon ten steps and another program can push the dragon five steps, make it 1.5 times faster. But then, there is not so much difference from one program pushed fifteen steps. His idea is just coping all the events and nothing more, still he can change the speed twice. However, if you learn the idea of generalization from mathematics, you will realize that which method can be applied to more situations. In this case, changing the speed itself in one program is better since you are not limited to multiple of positive integer (not only fractional times speed up, but you can stop and can also go backwards). If you learn computer science, the one program is considered better since the resource consumption of multi-threading, synchronization overhead, and so on. Also code maintenance point of view, one program is much easy to manage in general compare to the multiple copies of the program. Despite these disadvantages, I still like his idea, so free and unique.

When I saw 20 key events for handing four direction's control to speedup dragon five times faster (Figure 2), I was surprised by his idea, especially how freely and creatively he can think. At the same time, I felt the importance of the learning of basic concepts. I wish he will continue to learn without forgetting this thinking way, a free and creative way of thinking.

Figure 2. Using multiple same key events

No comments: