agsdix-fas fa-child

Regular Polygons

We draw regular polygons by selecting the number of sides with a knob.

info outline icon
Intermediate Activity; Repeat While; Cartesian Plane; Main Loop.

What are we going to do?

Are you a teacher?

Lesson Plan

Courses

  • Grades 6-12
  • 6th Grade – 12th Grade Courses

Materials

  • Cell phone, tablet, or computer
  • Internet connection

Description

In this activity, students can experiment with Protobject, learning visual programming and computer science in a safe and playful way.

Educational Objectives

  • Understand the concept of While (repeat while) in programming
  • Create a technological object (prototype) using a device
  • Identify relationships between technology and the surrounding world
  • Evaluate personal and peer work in individual or team tasks
  • Discuss and reflect on ideas for improvement

Start (10 minutes)

Welcome the students to the class and briefly introduce the day’s activity, “today we will learn to prototype a game with a balloon.”

We will start the class by providing technical knowledge to the students for meaningful learning of the practical activity.

To open the class, we can begin with a question:

Have you heard of “repeat while” in programming?

You can let the students propose their answers and then provide the correct response.

A “repeat while” loop, also known as “while” in English, repeats a block of code as long as a condition is true. The instructions within the block will be executed repeatedly until the condition is no longer true, meaning it becomes false. When this happens, the rest of the code continues to execute.

Let’s see an applied example. A regular polygon is defined as a polygon where all its sides and angles are equal. So, to draw one, you would have to draw all its sides the same size, making sure that the interior angles are also equal to each other.

So, how do we draw a three-sided one? You would have to draw three lines, forming an equilateral triangle. The same goes for a four-sided one, which would be a square. What if we wanted to make a ten-sided one? Or fifty sides? The work becomes quite tedious!

So, how do we draw it?

A property of polygons is that the sum of all their exterior angles is always 360°, regardless of how many sides they have. Since in a regular polygon all angles must be equal, we can say that one angle is equal to 360 divided by the number of sides.

So, let’s try drawing an equilateral triangle with a perimeter of 30: We draw a line of size 10, which is the perimeter divided by the number of sides. We rotate to the left by 120°, which is 360 divided by the number of sides. We draw another line of size 10. We rotate again by 120°. We draw the last line of size 10.

And we have a triangle!

Now, let’s use the “repeat while” block. If you notice, in the previous procedure, we have only two steps that are constantly repeated: drawing a line and rotating a certain number of degrees to the left.

But how many times do we have to do this?

Until we have drawn all the sides of the regular polygon!

So we can say that while we haven’t drawn all the sides, we must draw a segment and rotate a certain number of degrees to the left. These steps repeat until the condition is met! Having gone through all this reasoning, we are finally ready to program.

Let’s use the “Repeat While” block!

Finally, to start the prototyping process and make them feel like protagonists of their learning, ask them:

Shall we create a game to make it clearer?

Let’s think of a game where a balloon inflates more and more WHILE you keep pressing the touch button, and when it reaches a certain limit, it turns red and bursts!

Development (20-30 minutes)

Connect your equipment to the Protobject platform. For this exercise, we will use the TOUCH BUTTON, DRAW/ERASE, and SOUND PLAYER

Remember to experiment yourself beforehand to anticipate questions that may arise from the students.

You can follow the step-by-step code for the activity, and if you have any doubts, read the commented code.

To test the prototype, instruct the students to click on the activation button.

Congratulations!

Conclusion (5-10 minutes)

Now that we’ve implemented regular polygons with a knob… Let’s play with the values!
  • How can we change the perimeter of the figure?
  • What happens if we rotate to the right instead of the left?
  • How could we change the color of the lines along with the number of sides of the polygon?

Try modifying values to understand how it works!

agsdix-fas fa-book-reader

Learn

Do you know the concept of “repeat while” in programming?

A ‘repeat while’ loop, known as ‘while’ in English, repeats a block of code as long as a condition is true. The instructions within the block will be executed repeatedly until the condition is no longer met, meaning it becomes false. When this happens, the execution will continue with the rest of the code.

Regular polygons!

Let’s look at a practical example. A regular polygon is defined as a polygon where all its sides and angles are equal. So, to draw one, you would have to draw all the sides of the same size, ensuring that the interior angles are equal to each other.

So… how would you draw a three-sided polygon? You would need to draw three lines, forming an equilateral triangle. The same goes for a four-sided polygon, which would become a square. What if you wanted to create one with 10 sides? Or even 50 sides? The work becomes quite tedious!

How do we draw it?

One property of polygons is that the sum of all their exterior angles is always 360°, regardless of how many sides they have. Since in a regular polygon, all angles must be equal, we can say that one angle is equivalent to dividing 360 by the number of sides. So, let’s try to draw an equilateral triangle with a perimeter of 30:

  • We draw a line of size 10, which is the perimeter divided by the number of sides.
  • We rotate 120° to the left, which is 360 divided by the number of sides.
  • We draw another line of size 10.
  • We rotate again by 120°.
  • We draw the last line of size 10.

And we have a triangle!

Let’s apply the “Repeat While” block!

If you notice, in the previous procedure we have only two steps that repeat constantly: draw a line and rotate a certain number of degrees to the left. But how many times should we do this? Until we have drawn all the sides of the regular polygon!

So we can say that while we haven’t drawn all the sides, we should draw a segment and rotate a certain number of degrees to the left. These steps repeat until the condition is met!

Having gone through all this reasoning, we are finally ready to program. Let’s use the Repeat While block!

Make

Let’s create the prototype: we’ll need a smartphone and a computer/tablet.

1

Add the device Knob

2

Add the device WriteDraw by opening it on the same computer/tablet by clicking Open in this window (it’s more practical to draw the polygon on the computer than on another smartphone).

We are ready to start prototyping!

Composición del código

Click on question circle icon to open comments that explain the code.
agsdi-bulb-options

Desafío

Now that we’ve implemented regular polygons with a knob… Let’s play with the values!

  • How do we change the perimeter of the figure?
  • What happens if we rotate to the right instead of rotating to the left?
  • How can we change the color of the lines based on the number of sides of the polygon?

Try modifying values to understand how it works!

In the next activity, we will learn how to create a gentle blinking lighthouse.