Discuss the use of blocks in the Pen and Operator category
Explain the use of variables
List the steps to take input from the user
Discuss how to create simple games
Sure dear! You can
easily create scripts
in Scratch with
variables. Using
variables, this task
of maintaining a
scorecard can be
done easily. Come,
let me tell you
more about it
Mother, I want to make
game in Scratch
where the score is
shown to the player at
the end of the game
Can you help me?
USING THE PEN
Sprite’s pen is a feature that allows shapes
to be drawn according to the Sprite’s
movement. When the pen is down, the
Sprite leaves a trail as it moves, that is, it
draws.
| iiss osenGoceltneica te: ls ciabaalalThe various blocks under the Pen extension category help us draw
interesting shapes.
Follow these steps:
1. Click on the Add Extension
option in the lower left
corner of the Scratch
window. A number of
extensions appear.
2. Click on the Pen extension.
We will notice that a new
category Pen gets added to
the Blocks Palette. We can
use the blocks in the Pen
category to draw interesting shapes.
A Fig. 8.1. Adding Pen extension category
Let us briefly discuss the use of the various blocks in the Pen category.
Removes all pen marks and stamps on the Stage.
Puts the Sprite’s pen in down position. In this
position, the Sprite draws when it moves.
[7 =| Draws a copy of the Sprite on the Stage.Puts the Sprite’s pen in up position. In this
position, the Sprite does not draw when it moves.
Sets the color of the Sprite’s pen according to the
selected color.
‘Changes the color of the Sprite’s pen according
to the specified value.
Sets the color of the Sprite’s pen according to the
specified value.
Changes the size (thickness) of the Sprite’s pen.
Sets the size (thickness) of the Sprite’s pen.
Let us create and execute the following block stack to understand the use
of some of the blocks in the Pen category.
Cor
7
Pe)
A
cory
7
A Fig. 8.2 Using Blocks in the Pen category
Ze
Sprite leaves a Sprite does not
trail when the leave a trail when
en is down the pen is up
g a
a) |
oo
We will notice that the Sprite leaves a trail for the first 100 steps as the
pen is down. However, for the next 100 steps, the Sprite’s movement
leaves no trail as the pen is up.
+ Bt
| os_ctes Coe Connct Grade.5 0000 Otel 100
os.sap20 e191 Pu3,
-) Dennis Ritchie, an American computer scientist, created
foo the popular C programming language.
Python, R-language, Java, Lisp, JavaScript, Prolog,
we! Haskell, Julia, C++ and AIML (Artificial Intelligence Markup
oe
>
Language) are some programming languages used
extensively in Artificial Intelligence and Machine Learning,
CREATING SHAPES USING SPRITE’S PEN
Let us draw some shapes using the blocks in the Pen category.
Creating a Triangle
Create the following block stack for drawing a triangle with Sprite’s pen.
The turning angle for a triangle is 120 degree.
Without using repeat block Using repeat block
t he
Sake secre slecticn “ai fate nigalepalNote that the hide block has been used at the end of the block stack so
that the shape drawn can be seen properly.
Creating a Square
Create the following block stack with the turning angle of 90 degree to
draw a square
Without using repeat block Using repeat block
Ory)
ee
Lh
S 0
C:)
Creating a Circle
The following block stack draws a circle. The block in the
repeat block causes the pen color to change resulting in a colorful circle.
We can easily
create a figure with
nsides by letting
the turning angle
be 360/n.
Output
A Fig. 8.3 Block stack
for drawing a circleHSMAPCHECK oo... eee cette :
Create the following block stack. Draw the output in the box.
USING BLOCKS FROM THE OPERATOR CATEGORY
The blocks in the Operator category help us perform various operations
such as:
+ Doing calculations like addition |+ Comparing values like greater
(+), subtraction (-), ete. than (>), less than (<), etc.
t he
ian rakiacascsacte nts ceca sce ite ees)Create the block stacks as shown in Fig. 8.4 to
perform some calculations. Note the use of say
block to display the result of the operation.
Create the
block stack as
shown in Fig.
Py Pr, eae
8.5 to compare
values using blocks. Note the manner in
S ome
which these blocks have been used with
‘A Fig. 8.5 Using blocks the if block to form conditions.
A Fig. 8.4
from Operator category
VARIABLES
While creating games and animations in Scratch, we may need to store
and use some values such as points scored by a player, number of turns
and number of times the Sprite did something. These values can be
stored in variables
Avariable is a container that holds one value. This value can be a word
or a number. Consider the following example:
Score is a variable that holds the value 1 and Msg is a variable that holds
the value ‘Welcome’.
Score =1
Msg = ‘Welcome’
In Scratch, variables can
be local or global. A local
variable can be used by
just one Sprite whereas
\_ Welcome a global variable can be
used by all the Sprites in
the project.
Let us learn to work with variables.Creating and Using a Variable
Let us use the blocks in the Variables category.
1. Click on the Make a Variable |__| button in the Variable
category. The New Variable dialog box appears.
2. Type a name for the variable. For example, we have named the
variable ‘count’ as shown in Fig. 8.6.
3. Choose whether the variable will be used for all the Sprites (global
variable) or for one Sprite only (local variable)
4. Click on the OK button. The variable with the name ‘count’ gets
created.
A Fig. 8.7 Scratch window with the new variable
a a a aaa a biel tilidi il+ We can use the hide
variable block
or uncheck the box next to
the variable name to hide the
v|
display of variables value on the Stage.
* Right-click and choose delete variable
option to remove or delete a variable.
Create the block stack as shown in Fig. 8.8 that uses the variable ‘count’.
Value of count
variable is
displayed here
A Fig. 8.8 Working with variables A Fig. 8.9
Notice, when we execute the block stack, the value of the variable count
keeps on getting incremented by 1 as aa) block is placed
inside the forever block. Click on the red flag to stop the execution of the
script.
Now, execute the block stack (Fig. 8.9) and note that the value of the
variable ‘count’ is getting changed by 100 repeatedly.
+ Bt
Veit belecc ease oicehaca ade iel ness oulDrag the variable from the
Variables category to the
text area in the say block
to display the value of the
variable.
#SnapCheck ....
What does the Sprite say when the adjacent
block stack gets executed? What will happen if
we move the say block inside the repeat block?
TAKING INPUT FROM USER USING ASK BLOCK
We can display a prompt to the user and take his response using ask
block in the Sensing category. The response entered by the user is stored
in a variable answer.
Create the block stack
as shown in Fig. 8.10
in which the Sprite
prompts a question to
the user and checks
whether the answer
is correct or not. The
CAD) block from the
Operators category is
used to compare the
answer of the user with
the actual value.GENERATING RANDOM NUMBERS
Random numbers can be generated by using the block
in the Operators category. The random number generated is between
the two limits entered in the block. For example, the block
generates one random number between 1 to 10.
Let us use the say block to display the random value generated between 1
and 100 as shown below.
Variable: A storage area in ego: A symbol used
to perform operations like
memory to hold a value.
a addition and subtraction
#THR(O)WBACK
+ At
| stom citck Code Connect Gxade-S 20008 01nd 108. o5dep-20 820-0 Pu#LetUs @&@ &
A. Fillin the blanks using the words given below.
200 variable input 300 trail
Bp BF) is used to take from the user.
2. Goa) gives as the result.
3. When the block is executed, the Sprite leaves a
as it moves.
4. is used to store a value.
5. gives a random number between 200 and
Write ‘T’ for true and ‘F' for false statements.
1, The turning angle should be 90 degrees if we want
to draw a triangle using the blocks in the Pen category.
2. The pen color and size cannot be changed.
3. I> block can be used to compare two values.
4, When we execute the block [2 = ramen @ © B
a random value between 10 and 50 is stored in the
variable ‘a’.
5, Blocks in the Events category help us create and work
with a variable.
UU UL
Answer the following questions.
1. What is the difference between pen up and pen down blocks?
2. What is the use of blocks in the Operator category?
==)3. How can you generate a random number in Scratch?
4. Define variable.
5, Give the use of arn a
ae
222 #OpenForum
Aclass discussion on ‘Programming Languages’ can be taken up.
The discussion can cover the important aspects of a programming
language such as founder, important applications developed using it, any
other interesting facts.
block.
Y sneak
#88 sscreenshot
Consider the adjacent block stack and answer the
following questions:
1. Which variable has the same value as the
variable ‘answer’?
2. What value is stored in the variable ‘B’?
3. What shape is drawn when the block stack is
executed (assume the user input is 200)? Give the
dimensions of the shape
Mov
Lab Activity
1. Generate a random number between
1 and 10. Ask the user to guess the
number. If the user's guess is right
display the message ‘You guessed it
right’ otherwise display the message
‘Better luck next time.
+ CIID - ©
leecddeici iigainkienedinediedia