You can also use much simpler code to create simple polygons. Here’s code making a pyramid in Scratch. The program uses sine and cosine functions to draw triangles. To make the rotation work, code tells the pen to draw forever with orientation based on mouse position.
Here is code in Scratch that generates several regular polyhedra from a sphere. This code enerates those regular polyhedra (3D) that are made up of triangles. We also include the triangle (2D polygon) as a possible shape. We exclude the cube, which does not work well with this method. The program evenly spaces the points (corners, “vertices” of the shape) on a sphere. This demonstrates how the vertices of regular polyhedra fit on a sphere, and how the vertices are equally spaced from each other, making them very regular.
Golden rectangles inside icosahedron
Icosahedron inside dodecahedron