Lesson Progress

0% Complete

Now it’s time for applying this knowledge (we want to retain everything, don’t we?). you’ll write a script to draw a triangle instead of a square. One thing is sure – you can draw a triangle using the same script you wrote for drawing a square; all you must do is make certain changes here and there.

Let’s have a look at the changes to be made. A triangle has three sides instead of four. Therefore, you must repeat the **move () steps block**, **wait () secs** block, and **turn ‘clockwise’ () degrees **block three times, instead of four, i.e. you must change the number in the repeat block to **3**.

Now comes the angle. You cannot draw a triangle using only 90° (you can try if you want to!). there are different ways for drawing a triangle, but here we’ll stick to the easiest one, where you must use only one value for the angle. For that, you need a little bit of mathematics (a very tiny bit, promise!).

In geometry, a part of mathematics, there is a relation between the number of sides of a shape and its angles (exterior angles, to be precise).

The angle that used for drawing for drawing the square was also the exterior angle. Why are we concerned with it? This is why:

As you can see in the image, the sum of the exterior and interior angle is 180° because they form a straight line. From the different shapes, you can make out why it is necessary to use the exterior angle to draw, and not the interior angle.

Now, in a square, all sides are perpendicular to each other, i.e. the angles form the corners of the table. Therefore, they are 90°. And from what you learnt above, you can make out that both the exterior and interior angles are 90°. That is why drawing a square is very easy. But in the case of a triangle, this is not the case. In most of the triangles, all the three angles aren’t equal. In only one type, known as the equilateral triangle, all the angles are equal and are equal to 60°. Therefore, the exterior angle for this triangle becomes 120°.

But what if somebody asked you to draw any other shape? For that, we have a very simple, small, and sweet formula:

Where,

n = number of sides of the shape

Therefore, for a triangle:

While writing the script in the** turn ‘clockwise’ () degrees** block, instead of **90**, you’ll write **120**.

Below is the complete script for making a triangle:

Okay, it was not that tiny. But it was worth it! Now you can draw any shape using the same script. All you need to do is change the number of sides, calculate the exterior using the formula you just learned, and use this value.

Saving your script is as important as any other step while writing the script. Nobody wants to lose their hard work!

Follow the steps below to save your script:

- Click on the File tab on the toolbar.

- Then, select
**Save**from the drop-down menu. A pop-up window will open. - In the pop-up window that opens, select the folder where you want to save your file and then change its name to whatever you to. In the current case, you can keep
*How to Draw a Triangle*as the file name. - Finally, click on
**Save**. The file will automatically be saved with**.sb3**as its extension.

Your script is now saved! You can now load it in mBlock whenever you want!

Before you move on to the next lesson, a small assignment awaits you!

You have to write a Scratch Script which draws a hexagon (a shape with six sides) when you press the **D** key on your keyboard. Then you must save it and upload it to the website. Submitting the assignment is a must in order to receive the certificate after completing the course.

Submitting the assignment is a must in order to receive the certificate after completing the course.

Follow the steps below to upload your assignment:

- Click on
**Choose File**. - Select the file from the pop-up window that opens up.
- Once the image is selected, click on
**Upload Assignment**.

File types allowed is **SB3 **file generated from the Scratch program. The maximum file size allowed is 5 MB.

Good luck!