8
A Very Brief Introduction to Programming Using scratch By Hind Zantout Heriot-Watt University Dubai Campus The system can be downloaded here https://scratch.mit.edu/ 1- Introduction Launch scratch -> cat is visible in the middle of the screen areas of the scratch environment: stage sprites list blocks palette: Scripts, Costumes, Sounds current program (project) area green ‘go’ flag, red ‘stop’ button set language The main mechanism for most programs will be by using Scripts. There are different categories of Scripts (Motion, Looks, Sound, …) but the main ones for beginners are Motion, Control and Events. To write a program, just drag the relevant script to the current program area. Task 1 (observing) Make sure Scripts is selected and set to Motion Click-and-drag the cat along the stage, observe what happens to the go-to x: y: command and glide commands in the Motion Script. Explore the i information button of the sprite 2- Hands-on scratch Task 2-1 (controlling cat movement) Select the move-10-steps block into the current project area, then click on it -> the cat will move, note its new position Q.) Can you make the cat move 20 steps? Task 2-2 (rotating and changing direction) What is the effect of turning by 15 degrees?

Introducing Scratch

Embed Size (px)

Citation preview

Page 1: Introducing Scratch

A Very Brief Introduction to Programming Using scratch

By Hind Zantout

Heriot-Watt University Dubai Campus

The system can be downloaded here https://scratch.mit.edu/

1- Introduction

Launch scratch -> cat is visible in the middle of the screen

areas of the scratch environment:

stage

sprites list

blocks palette: Scripts, Costumes, Sounds

current program (project) area

green ‘go’ flag, red ‘stop’ button

set language

The main mechanism for most programs will be by using Scripts. There are different categories of

Scripts (Motion, Looks, Sound, …) but the main ones for beginners are Motion, Control and Events. To

write a program, just drag the relevant script to the current program area.

Task 1 (observing)

Make sure Scripts is selected and set to Motion

Click-and-drag the cat along the stage, observe what happens to the go-to x: y: command and glide

commands in the Motion Script.

Explore the i information button of the sprite

2- Hands-on scratch

Task 2-1 (controlling cat movement)

Select the move-10-steps block into the current project area, then click on it -> the cat will move, note

its new position

Q.) Can you make the cat move 20 steps?

Task 2-2 (rotating and changing direction)

What is the effect of turning by 15 degrees?

Page 2: Introducing Scratch

Q) What about turning by 90 degrees?

What is the effect of turning by -90 degrees?

What about combining steps and rotations?

Task 2-3 (slowing things down)

The movement above is too fast to see, and things can be slowed down with wait…secs from the

Control block from within Scripts.

Examine the more complicated movement.

Page 3: Introducing Scratch

Task 2-4 (mirror image to turn around)

First try out this code, replacing the turn…degrees instruction by point in direction…degrees instruction

This is not quite working out. To get a left-right flip rather than an up-down flip, you need to set the

correct rotation style (left-right) first and then rotate as before. This can be set in the i information

menu of the sprite to choose the rotation style that does that. It can also be set using the relevant set

rotation style left-right instruction in Motion.

Task 2-5 (repeating)

Go to Control again and make this whole block repeat 3 times.

Page 4: Introducing Scratch

Task 2-6 (launching)

You can now use the green flag to launch the program when the green flag is clicked. For that you need

to go to the Events blocks.

Task 2-7 (bouncing off the edge)

The cat can be made to move, and bounce when reaching the edge, but there may a problem –

depending on the rotation style being properly set or not. To get the problem, go to the information and

set the rotation style to rotate (not left-right).

To solve the problem, we must allocate a suitable rotation – similar to what we did in the earlier task,

but this time we use a block instead of the sprite information.

Page 5: Introducing Scratch

Task 2-8 (moving forever)

And here is the cat forever moving in a straight line and bouncing back at the edge

Task 2-9 (‘saying’ something)

And here is the cat sating ‘hello’.

3- Summary

Here is a summary of programming concepts were introduced so far.

Event-driven: when something occurs, such as the green flag being clicked, do some action. For that and

other events to program, you need blocks (light brown) from the Events sub-menu inside Scripts.

Repetition: you can repeat a set of instructions a number of times, or infinitely many times, or even until

a certain condition is met. For that, you need blocks (mustard colour) from the Control sub-menu inside

Scripts.

Waiting: you can hold up the program for a fixed period of time. This amounts to ‘repeatedly doing

nothing’ until the time has passed. Because of that you find the block (mustard colour) in the Control

sub-menu inside Scripts.

Selection: you have seen this so far only implicitly as part of the ‘if on edge’ instruction. In selection,

different instructions will be executed, based on some condition being met. More on this later.

Sequencing: the instruction are executed in the order in which they appear.

Page 6: Introducing Scratch

4- More Hands-On Examples

Task 4-1 (better movement with costumes)

Our cat has 2 costumes, more if you spend the time to create a third costume.

Now add a further movement.

Task 4-2 (adding another sprite)

Let’s add a parrot to scare the cat.

Find the parrot inside New Sprite in the Sprites area.

Shrink the parrot size, and place the cat and parrot on opposite sides of the stage.

Add this block of instructions to the parrot, make sure the parrot is selected, not the cat.

This is clearly not quite what we want, so add the same instructions to the parrot as we did for the cat.

Page 7: Introducing Scratch

Task 4-3 (sprites touch, sprites say something)

Now we need to add the selection instruction which tests when the cat touches the parrot, it should say

‘Miaow’. Here we need to use a block from the Sensing sub-menu inside Scripts to set the condition. We

also need a conditional if-then instruction which you can find as a block in the Control sub-menu inside

Scripts.

5- The Concept of Data and Mathematical Operations

Task 5.1 (multiplication and user answers)

Name data items num1 and num2 and set some values say 3 and 5. For the result data item, set it to the

product by using the green multiplication operator BEFORE dragging it into the empty result slot.

You get input by ‘sensing’. Remember the comparison of result to answer has to be carried out as an

operation first. Note that the answer needs to be transferred to a new data item (Your Answer).

Page 8: Introducing Scratch

Task 5.2 (multiplication using random numbers)

This is almost self-evident: you can generate random numbers. Note that the answer is not saved in a

separate data item. What is the consequence?