0% found this document useful (0 votes)
32 views11 pages

DocScanner 3 Mar 2024 6-48 PM

Uploaded by

ritesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
32 views11 pages

DocScanner 3 Mar 2024 6-48 PM

Uploaded by

ritesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 11
= Let’s Learn sing a script > to accept inputs from the user U: e the position of a sprite on stat SF > to determin > touse variables in a script ate advanced scripts u sing nested loops > to cre rites and backdrops: You ied 0 create and use your own spi ntrol blocks and apP u learnt t w to execute scripts repetitively using co! a ath Last year, YO so learnt ho al ffects to sprites. special e Let's see the following Script and recall some Of the blocks that we have used, Assuming that the given Script ji will show the dancing Ballerina, $x% K Accepting Inputs from the User Sensing blocks S Created for the Ballerina sprite, the Output ete) This category contains the blocks thai keyboard. ROE It displays an input box and Prompts the user to type the input. The input entered by the user is stored in the @ variable. let's see the following script using the Sensing blocks. tare used to accept inputs from the user/ G9 What's your name? )atniten| LU atc e Oa m Op e ETM Aes} When the green flag is clicked, the sprite will ask for ‘What's your name?” = Malt for an answer. Once the user enters an answer and clicks on the blue chee i the Sprite will display the entered name for 5 seconds. a Mar | Learning by doing Use the Sensing, Events and Looks blocks to input your favourite colour. Use a sprite to display your favourite colour. The script should also change the colour of the sprite to the same colour. Position of a Sprite X and Y co-ordinates The stage in Scratch can be divided into four squares using a horizontal and a vertical line. The four squares thus formed are called quadrants. The horizontal line represents the X-axis and the vertical line represents the Y-axis. The ‘x’ position determines the horizontal location of the sprite and ‘y’ position determines the vertical location of the sprite. The point at which the X and Y-axis meet is called the origin. The value of x and y at origin is zero. X=-240 Y= 180 xe-240 x=240 Ye -180 Ye +180 The value of x position of a sprite increases from 0 to 240 when it moves to the right from * he origin and decreases from 0 to -240 when the sprite moves t© the left from the origin, Similarly, the value of from 0 to 180 when it MOVEs up from Origin ar Tom the origin, Y Position of a sprite increases it ind it decreases from 0 to -18 when the sprite Moves down fj lecre: 0 You can show the above background on the stage by adding the Xy-grid from the list of backdrops. The Position of a sprite on the stage is decided by the Values of its x and y coordinates. n the stage it can happen that the sprite might f the stage and disappear. To avoid this, we can 2 se If on edge, bounce While moving @ sprite oO beyond the boundaries 0} the If on edge, bounce block. This block checks to see if the sprite is touching the edges of the stage, ang if it does, it will make the sprite turn back in the opposite direction, In the following script, the fish moves 10 steps and waits for 0,05 seconds, When it reaches the edge of the stage, it will change its direction insteaq of going beyond the stage boundary. Note that the set rotation style left-right block has been added to avoid the sprite from rotating vertically. a1 ees Dfeitars a vetia) eR ass ater id i Script Output of script Using Variable Blocks While creating scripts or programs, we often need to use vari bles to store values. A variable is a placeholder for some value, similar to th Nar er iables in Algebra. In Scratch, variables can be uniquely labelled by ena n be used by just one sprite or by all of your sprites. You, they © a "Ril See the Smeciiet grate ste Seer Sot cr mune: “The bie wil Same ger arreunt, socheas Stet or tre save: Rhices the Swecfiet arate tomthe Creating coh © Step 1: Select the Variables Vanes Sek Step 2: Click om Make 2 variable |” wena Step 3 Specify the name of the variabie ard dick AK Step 4: The name of the new variable BOIS WIRD F Prat Ran Pare ’t: : bs an} Can now see the blocks associated with the varatie, | | ou ni vari ow or hide its value on the Stag eck the variable to s| hid You can check and unch hi Assigning values to a variable / Use the set script block from the Variables group to assign values to the variable. Gea Whats your name? Jeno | | ° | Script Output | Changing the value of a variable Let's create a game in which you have to click on each fruit to put it in the bowl. Each time a fruit is placed inside the bowl, the score increases by 1. Create a new Scratch project and import the Bowl sprite. Create a new variable called score and add the following script. catsroro GD The given script increases the size of the bowl by 400%. It Positions the sprite at the specified location and also assigns an initial value of 0 to the variable score. ing scripts to it. id the sprite Strawberry from the library and add eee ita ‘he s first script puts the strawberry in the basket when it is clicked. W s clicked, the strawberry goes back to its starting position. green flag wrx @y @ | Add the sprite Orange from the library and add the following scripts fort | @ When the green flag is clicked, each fruit will be placed at th in its script. The user has to click on each fruit to place it in tl the ‘score’ variable will show the final score. re € Position SPecifieg he bowl, Atthe end, WR 3 ton | G-ede | Using nested loops In Programming, a nested loo; P refers toa looping structure forever block used inside anot such as a repeat or ther looping structure, F Word Galaxy ee. input variable nested quadrant Mind Map ask and walt blk ‘accepting input from the user ‘Advanced Features of Scratch 3 X and ¥ co-erdinates creating variables position of the Sprite ing values “near if on edge, bounce ing the value “Tice aE & QL. Tick the correct option. a Itrefers toa looping structure such as a another looping structure. Nested loop ii, input block repeat or forever block used inside ili, answer block & The block Category used for acce ting input from the user, "Looks ii, Sensing ili. Motion : i Stores the most recent keyboard input. "Value ii input ii, answer * What is need for variables i in Scratch? Explain with an example. What will be the output of the adjacent script assuming that you have created new variable runs = 0. QL. Writea script in Scratch to in; the keyboard and display it. Q.2. Create two variables - fruit and vegetable. Write a Script in s, to input your favourite fruit and vegetable, variables. Display the values entered. put your favourite sports Person usin cratch and save the result in the 2 » Create a game in Scratch where game should keep a score for tl display it at the end of the game. you have to burst a balloon, The he number of balloons burst and Add 10 different ‘balloon’ sprites on stage from the library. When a balloon is clicked, it should burst. Use a different costume to show the same and then make it disappear from stage. * Create a variable ‘score’. When a balloon is burst, the score should increase by 1. * _ Display the final score when all balloons have burst. Q4. Create a geometric Pattern using the nested loops. HOTS You know that the block changes the value of the specified variable by a given value. Find out what will happen if the value of the variable is a text value? Web Links httpsy//scratch.mit.edu/projects/editor/?tutorial=getStarted As on 09.08.2019

You might also like