All of the GraphicsPath manipulation is done in the Figure Class. The Graphics path stick figure is originally created in the constructor. When you create a GraphicsPath stick figure, you need to backtrack on lines you don't want connected, otherwise the program will add lines to fill the path. At the end of our constructor we also do some initial scaling and translation of our stick figure to shrink him and put him more in the center of the screen.

The Draw routine of the Figure class, rotates and translates the stick figure to make him appear he is doing cartwheels along the form. Below is the code for drawing the stickman. Here, the original graphics path is copied into the graphics path we are going to transform. The Point of rotation is the midpoint of the stickman calculated from the bounding rectangle of the graphics path. The RotateMatrix is rotated by 30 degrees around the midpoint of the stick figure each time the figure is drawn. Also the Translation Matrix is Translated 20 pixels in the horizontal direction each time the Figure is drawn. Both these matrices are applied to the graphics path and the path is finally drawn.

publicvoid Draw(Graphics g, int position){ // Get the original graphics path unrotated and untranslatedm_gp = (GraphicsPath)m_gpOld.Clone();// calculated the point to rotate around by calculating the midpoint of the // stick figurePointF thePoint = m_gp.GetBounds().Location;thePoint.X += m_gp.GetBounds().Width/2;thePoint.Y += m_gp.GetBounds().Height/2;// translate the TranslationMatrix an additional 20 pixelsTranslateMatrix.Translate(20, 0);// rotate the rotation matrix an additional 30 degrees around the current midpoint of the stick manRotateMatrix.RotateAt(30, thePoint);// rotate and translate the stick figurem_gp.Transform(RotateMatrix)m_gp.Transform(TranslateMatrix);// Draw the stick figure in DarkBlueg.DrawPath(Pens.DarkBlue, m_gp);}

The Form uses a timer to Invalidate the form every 1/5 of a second. This causes the Paint Event Handler to redraw every 1/5 second. The Form's Paint handler tells the Figure Object to draw and also draws a red line below the figure to make it appear as if it is cart wheeling on a tight rope. If the figure surpasses the form, the timer is stopped and a "The End" title is posted on the form. The position of the figure is also incremented.

A Restart button has also been added to allow you to restart the figure anytime through the cartwheel cycle. This button calls the Figure Class's Reset method to reset the transformation matrices and restart the timer.