Page 91 - TechPluse_C4_Flipbook
P. 91

Drawing a Square using REPEAT

                 In the previous example, a square was drawn by using Pen, Motion and Control

                 blocks. In order to avoid repetition of commands, REPEAT command is used. This
                 command reduces the number of lines of commands you need to write to draw a

                 figure. The Repeat block in the Control blocks menu is used to do this task. You
                 can drag the blocks and keep inside the Repeat block. Let’s draw a square using

                 the Repeat block.
                 Step 1     Click on Events blocks category               .

                 Step 2     Click and drag the      when     clicked   block to the script area.


                 Step 3     Click on Pen blocks category             .
                 Step 4     Click on       erase all  block and drag it to the script area and snap it to the

                            script.

                 Step 5     Next click on Control blocks category              .
                                                      repeat  10
                 Step 6     Click and drag the                      block to the script area. Snap it to the
                            script.


                 Step 7     Click on Looks blocks category               .

                 Step 8     Click and drag the  hide  block to the script area and snap it inside the
                            repeat block.


                 Step 9     Click and drag the          pen down  block to the script area and snap it to the
                            script.
                 Step 10    Click on the block          set pen color to   and drag it to the script area. Snap it

                             to the script. Click on the colour dot and choose a colour of your choice.

                 Step 11   Now we will have to click on Motion blocks category                     .
                 Step 12    Next drag the  move       10 steps  and  turn     15  degrees  blocks and snap them

                             inside the repeat block. When you position any block inside the repeat
                             block, it expands to fit the blocks. Change the steps from 10 to 100

                             mention to change the degree from 15 to 90.
                 Step 13    In the repeat block, click and change the number of repeats from 10 to
                             4. Why are we doing this? We know that a square has 4 sides.

                 Step 14    If you do not want the sprite to appear over the figure, you can end the
                             code here. But if you want to see both the shape and the sprite, snap the

                              show  block at the end of the code.



                                                                                       Programming in Scratch        89
   86   87   88   89   90   91   92   93   94   95   96