Displaying Text and Drawing a Square

10.07.2017 |

Episode #2 of the course Coding сoncepts with Scratch by Alan Cohen

 

In this lesson, you will learn how to display text and draw a square using the following blocks:

Say block: Displays text.

Think block: Similar to the Say block but displays text using a “think speech bubble.”

Ask block: Asks a question. The answer is stored in a variable named Answer.

Clear block: Erases whatever is drawn on the screen.

Pen Down block: Analogous to pen on paper.

Move block: Moves a sprite a specific number of steps. Since the Pen Down block is in use, the sprite leaves a line as it moves.

Turn block: Turns the sprite the specified number of degrees.

 

Displaying Text and Accepting Input from the User

Programs display text. They communicate with their users—for example, presenting instructions to the user, asking questions, etc. Use the Say, Think, and Ask blocks to display text.

Say Block and Example

The Say block is accessible from the Looks block palette.

The following example displays the text, “Hello.”

The Say For Secs block displays a message for the specified time and then disappears. The following example displays the text,“Hello,” for 2 seconds and then disappears.

In this example, the cat sprite shows the text.

Think Block and Example

The Think block is like the Say block. It is accessible from the Looks block palette.

The only difference is the speech bubble that contains the text.

The Think For Secs block displays the text you enter for the specified time and then disappears.

Ask Block and Example

The Ask block displays text and waits for the user to enter a response. The Ask block is accessible from the Sensing block palette.

A field appears at the bottom of the stage for the user to enter their answer.

The answer is stored in a variable named Answer. This variable is accessible from the Sensing blocks palette.

Variables store information. A later lesson will discuss variables in depth.

You display the content of the variable using the Say or Think blocks. To do this, drag and drop the Answer variable into the text area of either the Say or Think blocks.

Congratulations! You created your first program. Let’s continue our journey and code a program that draws a square.

 

Drawing a Square

Before you code, it is a good idea to write, in plain English, what your program needs to do. This lets you figure out how to do what you want to do and determine the appropriate Scratch blocks for each step. For example, to draw a square, you need to:

1. Specify a way for the user to start the program.

2. Clear the screen each time the program runs.

3. Use a pen to draw.

4. Understand the problem: drawing a square. A square is a four-sided shape. Each side is equal in length. The angle between any two lines is 90 degrees.

5. Draw a line of a specified length.

6. Turn 90 degrees.

7. Draw a line of a specified length.

8. Turn 90 degrees.

9. Draw a line of a specified length.

10. Turn 90 degrees.

11. Draw a line of a specified length.

12. Turn 90 degrees.

You now have the steps you need to draw a square. Let’s transfer what we wrote in plain English into Scratch code.

1. Drag and drop when green flag clicked to the script area.

2. Click Pen.

3. Drag and drop Clear to the script area.

4. Drag and drop the Pen Down block to the script area.

5. Click Motion.

6. Drag and drop Move to the script area.

7. Change 10 steps to 100 steps.

8. Drag and drop either the Turn Left or Turn Right block.

9. Change 15 degrees to 90 degrees.

10. Repeat Steps 6 through 9 three times to draw the other three lines. Your complete program should look like this.

11. Click the green flag to run the program.

You probably noticed that you repeated a set of steps three times. Seems a bit tedious, doesn’t it?

If you think that there’s a better way, you’re right. The next lesson introduces you to repetition that makes it easy for you to repeat a set blocks.

 

Recommended book

Code Your Own Games!: 20 Games to Create with Scratch by Max Wainewright

 

Share with friends