|
|
|
< regular polygons |
Irregular Polygons |
colour > |
|
|
// a pythagorean triangle This simple program needs a little explanation. The curly brackets indicate the start and end of the polygon. The first corner of the polygon is drawn at the turtle's position when the polygon starts, so when drawing a triangle we need only specify the remaining two corners. This is done with the corner command ^, which tells the turtle to walk forward one unit and draw the next corner there. In our program we are using the combination keyword ^* to draw sides of different lengths. When the polygon is closed, the last side is automatically drawn between the first corner and the last. There is no limit to the number of sides a polygon can have (after a while Windows gives up on trying to fill them, but that limit is very high), and you can put a lot of code between the start and end brackets. You can even draw new lines or polygons as you go. The polygon is actually drawn by a baby turtle whose program starts and ends with the curly brackets. So when the polygon is finished the parent turtle is still in the same place, facing the same direction etc.
|
|
< regular polygons |
colour > |