AI Tutor
How do video games draw thousands of perfectly symmetrical shields, crystals, and arenas in milliseconds?
They don't draw each line by hand β€” they follow an algorithm, which is a precise set of step-by-step rules executed in order.

Drawing Regular Polygons with Loops

A regular polygon is a 2D closed shape where all sides have equal length and all interior angles are equal.
In the late 1960s, computer scientist Seymour Papert created Turtle graphics to let students control an on-screen pen using simple movement algorithms.
To draw any regular polygon with nn sides, the pen moves forward and turns by the exterior angle, which is 360∘n\frac{360^\circ}{n}, repeating nn times until it returns to where it started.
For a regular hexagon with n=6n = 6 sides, the turning angle is 360∘6=60∘\frac{360^\circ}{6} = 60^\circ at each vertex.
Let's trace this polygon algorithm step-by-step in pseudocode before running it.
What if we make a mistake and turn by the interior angle instead of the exterior angle?
A common mistake is turning 180βˆ˜βˆ’exteriorΒ angle180^\circ - \text{exterior angle} (the interior angle), which causes the pen to fold inward into a star or zigzag instead of completing the closed outer perimeter.
Once a shape is drawn, how can a computer move, flip, or spin it across the screen?