PROGRAMMING IN SCRATCH

 INTRODUCTION

Scratch is developed by the Lifelong Kindergarten Group at the MIT (MASSACHUSETTS INSTITUTE OF TECHNOLOGY), Media Lab, led by Mitchel Resnick in 2003. Scratch is used in more than 150 countries and available in 40 different languages.

Scratch is a visual programming language that allows you to create your own interactive stories, games, art and animations. As students design Scratch projects, they learn to think creatively, reason systematically, and work collaboratively. 

Scratch can easily run on different operating systems including Windows, Mac OS, and Linux. Scratch is easy to learn and use. It provides an interactive environment to create programs by just dragging blocks of code.

In the previous class, you have learnt about the different actions a sprite can perform on the scratch stage. And you have also learn that how to change the background, colour, direction, costume, etc. of a sprite. 

 MAIN COMPONENTS OF SCRATCH

Sprite: Sprite is a small graphic character that performs actions in a Scratch project. Scratch provides number of in-built Sprites. Cat is a default Sprite in Scratch.

Stage: It is the main working area where the Sprite moves and performs actions as per the given instructions. Here you can watch stories, play games, and run Scratch projects that you have created. It is divided in x, y co-ordinates. The value of both the co-ordinates are displayed at the bottom right corner of the stage. These co-ordinate indicate the position of the Sprite on the stage. 

Sprite List: It displays the thumbnails of all the Sprites used in a project.

Presentation Mode/ View full screen mode: Presentation Mode or View full screen  mode 

button is located at the top left corner of the stage. Click on the button to view the presentation of your project in full screen mode.

Choose Sprite: Scratch contains many exciting in-built Sprite options as per given. You have to just click on Sprite which you want to enter and it directly added to Scratch as your new Sprite. 

                                                                              


Script: Script is a collection of step-wise instructions that are given to a Sprite to do a specific task. a script consist of at least two blocks. 

                                                 

Scripts Area: Script area is a place where you create a Script for a Sprite to do a particular task. The script is created by dragging the instructions from the blocks palette and dropping them step wise on top of each other. Script is also called a Program. 

Let us learn how to drag and drop the blocks on the Script area:

Step 1: Left click on particular block.

Step 2 : hold and drag mouse to script area.

Step 3 : drop that block./ Release Left click.


CREATING A NEW SPRITE USING PAINT EDITOR: By clicking on paint button, The Costume window appears where you can draw and paint your own Sprite. Use given tools to draw a Sprite. The new Sprite appears on the stage and gets added to the Sprite list. You can drag and move the Sprite on desired position on the stage. You can use Zoom buttons to increase or decrease the size of the Sprite.


MOVING A SPRITE: All the instructions related to the movement of Sprite are given under the Motion block menu.we use motion scripts for moving task.

Create your first Scratch Project to move the Sprite in circular motion.

Step 1 : Open Scratch Program from Start menu or you can directly open it from desktop icon if it was there.

Step 2 : Select Motion block for script dragging. By default motion block is selected first in the list of different categories of scripts block. 

Step 3: Just drag and drop turn script. 

Note: You can check your Output by clicking on script in Script Area. you can follow video given below.



You will notice that Sprite will moves the specified number of steps. After drag and drop of this block of motion our Sprite will turn 15 steps in Circular Motion.

If we want back step of Sprite than just give numbers with (-) sign. example given below.


SENSING: The Sensing block palette has light blue color coded blocks, which are used to sense the keyboard input while executing the script. Let us create a small block stack by using the Sensing instructions and execute it.


USING MATHEMATICAL OPERATORS IN SCRATCH:  Blocks in Operator block category are round in shape. They are light green colour coded blocks and are used to solve mathematical equations. These blocks can easily be placed in the value box of any other block. Let us perform calculations in a Scratch project: 


You see that in video addition is performed there. Likewise, you can also perform Subtraction, Multiplication, Division. Which are basic mathematical operations. 


COMPARING VALUES: In mathematics, you use less than (<), greater than (>) and equal to (=) sign to compare two numbers. Similarly in Scratch, the (equal to) block reports true if two numbers are equal, the (less than) block reports true if the first value is less than the second value and the (greater than) block reports true if the first value is greater than the second value. These blocks are known as Comparison blocks. Let us try the comparision blocks:


GENERATING RANDOM NUMBERS: We can also generate a random number from a specified range by using the block from the Operators block category. Let us see how the Sprite itself choose the random numbers with the help of this block. 


CHANGING LOCATION RANDOMLY: You can also use the  block to specify any random location of a sprite on the stage.

Step 1: Delete the cat Sprite and add Starfish Sprite on the stage.

Step 2: Adding block on the Motion block will randomly change the x and y co-ordinates of the sprite's position on the stage. 


BOUNCING THE BALL RANDOMLY:  



COUNTING LENGTH OF WORD: Scratch blocks provide the facility to count the letters that are used to form a word. For example, the word Encyclopedia has 12 letters. Let us create a script to display the total number of letters as shown in video.


MAKING A VARIABLE: A variable is a placeholder in Scratch's memory that is used to store a changing value. Variable can hold one value at a time. These values can be either numbers or Strings (text). In Scratch Data block is used to create variables in a project. Variables are  represented by blocks shaped like elongated circles, uniquely labelled by the user. Let us observe the complete process of creating a variable.

Steps to make a variable:

Step 1: In the Data block palette, click on Make a Variable block. The New Variable box appears.

Step 2: Type any suitable name like 'Name' for the variable in the Variable Name text box as shown in figure video. 

Step 3: Select button specifying whether the variable is For all Spirites or For this sprite only. Click Ok.


APPLYING CONDITION IN PROGRAMMING: A condition is applied to put a check in a problem. It allows the program to select an action, based upon the user's input. Scratch provides various blocks enabled with conditional programming concepts. In Scratch 'if ', 'forever if ', 'if else ' are the conditional blocks present in the Control block category. The script inside the 

block will execute, only if condition given after if is true.

All the elongated diamond shaped blocks which are in Sensing block palette are placed as conditions inside these blocks. You can use blocks from the Sensing category for controlling the Sprites in a better manner.

Now we are looking it in example as given below.


Thank You for reading this blog...

Please give your valuable feedback.

Comments