We started by recapping how to calculate the vertex angle:
360 / n, where n is the number of vertices
She has indeed forgotten all about this calculation, but she remembered the number 360.
Then we started working on the actual function. After maybe 15 minutes of discussion and typing (5 mins allocated for picking a name as always) we came up with
let polygon k=r k (s [fd 50,rt (360 /k)])
Dead simple for a coder but daunting for a 4-year old. When explained, it's not very complex yet. To draw a polygon with k number of edges, you repeat the following k times:
- Move forward 50 pixels
- Turn right (360 / k) degrees
So, it was hard but it paid off. After struggling with the first polygon as in
polygon 6
She got crazy and drew all polygons up to 14 edges. Then they didn't fit into the Turtle Roy display anymore and we had to change her program a bit using the Turtle Roy "editor mode": we added fd 20 and lt 180 to the start so that she can squeeze in a couple more polygons. You can check out the end result here.
She was indeed so enthusiastic about polygons that she gave Mom a lesson too. Together they hacked the program so that it moves only 10 pixels at a time, so that they can draw the King of Polygons: the Hectogon. It looks like a circle, actually.