Thursday, 26 December 2013

Learn to juggle, not a Juggler's way

My  previous post explained how Scratch programming blocks were snapped together to make a simple animation. For convenience sake, the script is reproduced below :

Always remember that the blocks are executed one at a time in succession. In conclusion, placement of the blocks over another is crucial. The “go to x: () y: ()” block is first carried out when the “Green Flag” button is clicked, followed by “move () steps”, and so on.

At some point, the rule does not hold depending on your application. Try re-position or juggle any of the blocks within the “forever” block in the above script. The animation may look the same to our naked eyes, but it makes a lot of difference as far as the script is concern.

Continuing with the above script, let’s add some graphics to embellish the backdrop. Click on the “Stage” and then the “Background” tab.


Click on the “Edit” button and the Paint Editor appears. Import the graphics from the built-in library.


You can select any of the images from the various folders. Select “woods” under the Nature folder for the purpose of this practice. Shrink the sprite by clicking on the “Shrink” button and your stage should look like below.

Note : Don't forget to click on the sprite when the “Shrink” button is pressed. Clicking only the 
           "Shrink" button does not minimize the size of the sprite.


That’s not the end. You can add sound, another sprite ,etc to make it more lively. Your imagination is the limit. 

Let’s add a sound “meow” to the cat whenever it hits the edge. Click on the “Sound” button on your left. If you do not see the “play sound (meow)” block on your screen but “play sound (pop)” instead,   that means you are still in the “Stage” Script Area. Click sprite1 (the cat) and it should appear above the Script Area as shown below 



Drag the “play sound (meow)” block and insert it below the “if on edge, bounce” block. The script should look like below :


Start the animation by clicking the “Green Flag” button. Oops !!! We got a bug.
Click the “Stop” button on the far right above the stage area.

The cat keeps "meowing" non-stop and we wanted it to "meow" ONLY when it hits the edge.
This is where the "decision making" blocks come into play. Creating a flow chart helps make the picture clearer.


We will add two blocks shown below, an “ if ” block for decision making, a “touching (edge)” to sense the edge


Snap the "touching (edge)” block into the blank space of the  “ if ” block. The final script should resemble below 


Trying exploring with with your own imagination with more blocks and sprites.
Happy Scratching