Ejemplo n.º 1
0
        private void DrawLine()
        {
            this._state = RenderState.RenderInProgress;

            i++;
            if (i > iMax)
            {
                ResetVars();
            }

            this.t  = this.i.ToRadians();
            this.ot = (this.i - 1).ToRadians();

            x1 = xCenter + ((ra - rb) * System.Math.Cos(t) + ch * System.Math.Cos(((ra - rb) / rb) * t));
            y1 = yCenter + ((ra - rb) * System.Math.Sin(t) + ch * System.Math.Sin(((ra - rb) / rb) * t));
            x2 = xCenter + ((ra - (rb * P2Offset)) * System.Math.Cos(t) + (ch * P2Offset) * System.Math.Cos(((ra - (rb * P2Offset)) / (rb * P2Offset)) * ot));
            y2 = yCenter + ((ra - (rb * P2Offset)) * System.Math.Sin(t) + (ch * P2Offset) * System.Math.Sin(((ra - (rb * P2Offset)) / (rb * P2Offset)) * ot));

            P1.X = (float)x1; P1.Y = (float)y1;
            P2.X = (float)x2; P2.Y = (float)y2;

            if (i == 1)
            {
                fx1 = x1; fy1 = y1;
                fx2 = x2; fy2 = y2;
            }
            else if (i > 3)
            {
                try
                {
                    using (SolidBrush brush = new SolidBrush(clr1.Color))
                        using (Pen linePen = new Pen(brush))
                            this._gfx.DrawLine(linePen, P1, lP1);
                    using (SolidBrush brush = new SolidBrush(clr2.Color))
                        using (Pen linePen = new Pen(brush))
                            this._gfx.DrawLine(linePen, P2, lP2);

                    if (x1 == fx1 || y1 == fy1 || x2 == fx2 || y2 == fy2)
                    {
                        // If we manage to actually reach the exact spot where we started,
                        //   then wait five seconds and start a new shape.
                        Thread.CurrentThread.Join(5000);
                        ResetVars();
                    }
                }
                catch
#if DEBUG
                (Exception ex)
#endif
                {
#if DEBUG
                    System.Diagnostics.Debug.Write("Fatal error: " + ex.ToString());
#endif
                    throw;
                }
            }

            lP1.X = P1.X; lP1.Y = P1.Y;
            lP2.X = P2.X; lP2.Y = P2.Y;

            if (i == 400)
            {
                SaveVars();
            }

            clr1.CycleColor();
            clr2.CycleColor();
        }