Download Scratch – Handson Introduction 1. Boardwalk Purpose: Scratch

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Location arithmetic wikipedia , lookup

Addition wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
Scratch – Handson Introduction
1.
Boardwalk
1.1
Purpose:
 Scratch basics
 Animation
Create a new scratch program
Use the available sprite
1.2
Add the forever loop from control menu, add
move 10 steps from Motion menu
Click to activate
1.3
Change the code to check if sprite touches the
edge and bounce back.
1.4
Change properties of sprite to face only left and
right.
Add the following:
The wait and next costume imitate a cat that
walks.
1.5
Import from built-in images the boardwalk
background for the stage
1.6
Add the following at the top. This will make sure
the movement looks realistic.
1
dbe – Scratch Training
1.7
Combine all with the green flag hatter block to
start.
1.8
Add the following before the code:
If on edge bounce. The cat will say “hello” every
time after it bounced back off the edge.
2
dbe – Scratch Training
2.
Balls and bat
2.1
Purpose:
 Using multiple sprites
 Independence of sprites – sprites as objects
 Cloning of sprites
 Interaction of sprites - sensing
Create a new scratch program
Change
2.2
Change the sprite costume to a ball.
Name it ball. Add the forever loop ,
green flag and let the ball turn
2.3
Add another ball sprite and call it ball2.
Use code of first ball.
Note that here an if tests if ball2 touches
ball and also turns 1800.
The green flag at both the scripts will
mean that they move simultaneously.
2.4
Add the following to test if the first ball
touches ball2 and turns 1800.
2.5
Add another script and call it bat.
NEW. A variable count is created. It
counts how many times any ball touches
the bat.
3
dbe – Scratch Training
to
2.6
The bat can turn randomly. The code
checks if the bat touches either of the
moving balls.
Note all the sprites are moving at the
same time.
4
dbe – Scratch Training
3.
Conversation
3.1
Purpose:
 synchronisation of conversations
 user input in a conversation
 use of variables.
Create a new
Scratch program
and choose 2
human characters
as your protagonist
sprites.
Start each sprite’s
script with a
“When green-flag
clicked” hatter
block. This is vital
so that you can
start the two
sprites together.
Man
3.2
Start the
conversation with
one sprite saying
hello, and the
other replying, etc.
Test (by running
the program) that
the timing is such
that they speak
alternately.
3.3
Change the script of the
second sprite to respond by
asking other’s name. This
must be entered from
keyboard by the user!
To get the 2 sprites to
continue together (you never
know how long the user will
take to think up a name and
enter it) you must send a broadcast that will resume the
conversation.
5
dbe – Scratch Training
Girl
3.4
Both sprites now
start with a “when
I receive
broadcast” hatter
block. This
synchronises their
action.
3.5
Similarly, both
must pause again
when the user is
asked for the
second name, and
the conversation
must be resumed
in a synchronised
manner, again with
a broadcast.
3.6
Activity – INSTRUCTIONS FOR TASK:
One day you are in a beautiful spot. You see a boy/girl and start chatting. The conversation is about the
weather and you are asked about the temperature. When you supply that information, the other person
replies that he/she is from the USA and does not know Celsius, only Fahrenheit. So you give an estimated
temperature in F.
4.
Shapes
4.1
Purpose:
 Use the Pen commands
 Apply a methodology that involves the use of specific cases to determine the general
case.
Create a new sprite with paint option: just a
simple block
Start script with a “When Green Flag clicked”
hat block
Place sprite at 0, 0
Face sprite looking right (90)
Explain the role of the “pen”: Will leave a line
even when moving to 0, 0. Therefore lift pen
up before moving. As new lines get drawn
over the old ones, you have to clear the paint
area before starting a new run.
6
dbe – Scratch Training
4.2
Draw a equilateral triangle – 60 steps, turn
(How many degrees? – Get input from group!
– 120)
Another 60 steps, another turn, another 60
steps to complete the triangle
4.3
Reinforce loops by replacing the repetition
with a loop (3 times)
4.4
Use the existing code and make changes to
draw a square. Angle of turn? (Ask
group! – 90)
Use the existing code and make changes to
draw a pentagon. Angle? (72)
Is there a relationship between the angle and
the number of sides? What is it?
(360/numSides)
4.5
Create a variable “numSides” and change
script to include user input for the number of
sides. Use formula to determine angle. Try
various shapes (10 sides, etc. But be wary,
when the number of sides gets bigger, the
shapes will distort the moment the line hits
the sides of work area. (Reduce number of
steps accordingly (to 40, or less). Also try a
shape with 180 sides reduce steps to 2).
4.6
Create a variable “sideLength” and change
script to include user input for the length of
the sides.
4.7
“Doilies”
Sides
3
4
5
angle
120
90
72
To spin a doily the starting direction of each
shape must change so that the shapes
complete a revolution.
7
dbe – Scratch Training
= 360/3
=360/4
=360/5
4.8
Let’s call this change “deltaAngle”. Create the
variable “deltaAngle.
Insert a loop around the part of the script that
draws the shape.
Note that “deltaAngle” depends on the
number of shapes.
In the outer loop insert the turn command to
change the start direction of each successive
shapes.
4.9
Input
Enter the number of sides: 3
Enter the length of the sides: 100
Enter number of shapes to spin: 30
Output
4.10
Input
Enter the number of sides: 6
Enter the length of the sides: 50
Enter number of shapes to spin: 20
Output
4.11
Activity: Four-Square Challenge
8
dbe – Scratch Training
The four-square challenge
Write a program to draw the following:
The top-left corner coordinates and side lengths (steps) are:
Square
black
red
blue
Green
x-coordinate
-200
-80
10
30
y-coordinate
-20
40
70
20
steps
110
80
40
160
Note: Most educators will follow a linear approach to solving this problem i.e. they will use one pen and
draw one square after each other. They will loft the pen, change the colour and set the start coordinates
then put the pen down between drawing square two to four.
Use this opportunity to draw the squares using four pen sprites each with its own colour, each draw only
one square. Insert a delay inside the loop that draws the square to illustrate multithreading. Encourage the
linking of theory to practical where the opportunity to do so arises. Other topics that can be discussed are
parallel processing, timesharing etc.
9
dbe – Scratch Training
5.
Lists
Purpose:
 Introduction to lists (arrays)
 Basic operations with lists: filling (entering) and reading
 Searching and selecting
5.1
Filling the list:
 Use “Make a list” in the Variables tab, call it “numbers”.
 Use any character as your sprite and place him/her in the bottom left-hand corner of the output window.
 Delete all of numbers of the script in the beginning (otherwise it adds more and more numbers to the list
each time you run the script).
 Fill the list with random numbers (in Operators tab).
 When executing this script, you will see the list filling on the right of the output window.
5.2
Reading the list:
There are no FOR-loops in Scratch! You have to create your own loop variable (i) and initialise and change it
yourself!
The sprite will the “read” them one-by-one.
5.3
Selecting from and searching in the list:
The first part demonstrates selection, checking what element is at a particular position.
The second part searches the list and reports whether a number is in the list or not.
Both sections demonstrate nested concatenation of output, mixing string sections with variables.
5.4
Activity
 Create a list of 15 random numbers between 1 and 1000.
 Add instructions to the background that by presssing the letter “S” the sprite will give you the SUM and
AVERAGE of all the numbers.
 Add instructions to the background that by presssing the letter “H” the sprite will give you the highest
number in the list and by pressing “L” the lowest of all the numbers.
 Write the code for the sprite to add all the numbers (in a variable calles “sum”) and then divide it to get the
avareage when the letter “S” is pressed. Make the sprite output that for 5 sec.
 Write similar code to work out the highest and the lowest number in the list and make the sprite output
them.
6.
Use the keyboard to control the movement of a sprite
6.1
Create a new scratch program
Use the cat script
6.2
To use the up-arrow key to
move a script up. This moves
the sprite up.
10
dbe – Scratch Training
6.3
Copy these code three times
and changes it to move the
sprite down. Add the green
flag to activate all at the same
time.
6.4
Moves the sprite left
6.5
Moves the sprite right.
6.6
To draw lines on screen.
Position the sprite and clear
the screen.
11
dbe – Scratch Training
7.
Mouse control
7.1
Create a new scratch program
7.2
Add the following to the cat
sprite - to use the mouse as a
controller so that the cat is
following the mouse pointer.
Note the speed of the cat.
7.3
Add now the following to the
dog sprite. Note that the
speed of the dog must be less
(at least half) than the cat’s.
7.4
When you run the program
move the mouse pointer so
that the cat follows the mouse
pointer and the dog follows
the cat.
Make use of two sprites – cat and dog. Name them cat and dog
respectively.
_______________________________
12
dbe – Scratch Training
________________
13
dbe – Scratch Training