Practice Mission

How to draw a Triangle?

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).

interior-exterior-angles

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

triangle-int-ext-angles

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:

Exterior angle formula

Where,

n = number of sides of the shape

Therefore, for a triangle:

Exterior angle formula-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:

triangle ScriptTriangle

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 the Script

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:

  1. Click on the File tab on the toolbar.
    Save Menu
  2. Then, select Save from the drop-down menu. A pop-up window will open.
  3. 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.
  4. 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!

Assignment 1.1

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:

  1. Click on Choose File.
  2. Select the file from the pop-up window that opens up.
  3. Once the image is selected, click on Upload Assignment.
evive Alert
File types allowed is SB3 file generated from the Scratch program. The maximum file size allowed is 5 MB.

Good luck!