figure building sierpinski triangle main(the first thing sierpinski does is draw the outer triangle nextthere are three recursive callsone for each of the new corner triangles we get when we connect the midpoints once again we make use of the standard turtle module that comes with python you can learn all the details of the methods available in the turtle module by using help('turtle'from the python prompt look at the code and think about the order in which the triangles will be drawn while the exact order of the corners depends upon how the initial set is specifiedlet' assume that the corners are ordered lower lefttoplower right because of the way the sierpinski function calls itselfsierpinski works its way to the smallest allowed triangle in the lower-left cornerand then begins to fill out the rest of the triangles working back then it fills in the triangles in the top corner by working toward the smallesttopmost triangle finallyit fills in the lower-right cornerworking its way toward the smallest triangle in the lower right sometimes it is helpful to think of recursive algorithm in terms of diagram of function calls figure shows that the recursive calls are always made going to the left the active functions are outlined in blackand the inactive function calls are in gray the farther you go toward the bottom of figure the smaller the triangles the function finishes drawing one level at timeonce it is finished with the bottom left it moves to the bottom middleand so on the sierpinski function relies heavily on the getmid function getmid takes as arguments two endpoints and returns the point halfway between them in additionthe code has function that draws filled triangle using the begin_fill and end_fill turtle methods this means that each degree of the sierpinski triangle is drawn in different color recursion