Пример #1
0
        /// <summary>
        /// Performs the rendering of the <c>Lissajous</c> curve on this panel.
        /// </summary>
        /// <param name="dc">Graphics context to render on.</param>
        protected override void OnRender(DrawingContext dc)
        {
            const int MaxPens     = 5;
            double    semiWidth   = this.ActualWidth / 2;
            double    semiHeight  = this.ActualHeight / 2;
            double    scaleFactor = this.ScaleFactor;

            if (this.TheGenerator == null)
            {
                return;
            }

            SimpleTransform transform = new SimpleTransform(semiWidth, semiHeight, scaleFactor, scaleFactor);
            Pen             thinPen   = new Pen(Brushes.DarkGray, 1.0f);
            double          y         = transform.DirectY(this.TheGenerator.PointNow.Y);
            Point           pointEast = new Point(0, y);
            Point           pointWest = new Point(this.ActualWidth, y);

            dc.DrawLine(thinPen, pointEast, pointWest);

            double x          = transform.DirectX(this.TheGenerator.PointNow.X);
            Point  pointNorth = new Point(x, 0);
            Point  pointSouth = new Point(x, this.ActualHeight);

            dc.DrawLine(thinPen, pointNorth, pointSouth);

            Point last = new Point(0, 0);

            Pen[] pens = new Pen[MaxPens + 1];
            for (int j = 0; j < MaxPens; j++)
            {
                var pen = new Pen(Brushes.LightGreen, MaxPens - j);
                pen.StartLineCap = PenLineCap.Round;
                pen.EndLineCap   = PenLineCap.Round;
                pens[j]          = pen;
            }

            int i = 0;

            foreach (var point in this.TheGenerator.Tail)
            {
                int index = i / 10;
                if (index >= MaxPens)
                {
                    index = MaxPens;
                }

                Point p = transform.Direct(new Point(point.X, point.Y));
                if (i > 0)
                {
                    dc.DrawLine(pens[index], last, p);
                }

                last = p;
                i++;
            }
        }