Пример #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++;
            }
        }
Пример #2
0
        /// <summary>
        /// Renders the vertical moving composing sinusoid.
        /// </summary>
        /// <param name="dc">Graphics environment where to render.</param>
        /// <param name="toRender">Enumeration of points to render.</param>
        protected void RenderVertical(DrawingContext dc, IEnumerable <LissaPoint> toRender)
        {
            //this.ClipToBounds = true;
            if (this.Lissajous == null)
            {
                return;
            }

            double          semiWidth    = this.ActualWidth / 2;
            double          scaleFactorY = this.ActualHeight / this.Lissajous.TheGenerator.DeltaTimeHeadTail;
            SimpleTransform transform    = new SimpleTransform(semiWidth, 0, this.Lissajous.ScaleFactor, -scaleFactorY);
            Pen             thinPen      = new Pen(Brushes.DarkGray, 1);

            this.Render(transform, thinPen, dc, toRender, (point, startTime) => new Point(point.X, point.T - startTime));
        }
Пример #3
0
        protected override void OnRender(DrawingContext dc)
        {
            if (this.Lissajous == null)
            {
                return;
            }

            this.ClipToBounds = true;
            if (this.Lissajous.TheGenerator != null)
            {
                double semiWidth  = this.ActualWidth / 2;
                double semiHeight = this.ActualHeight / 2;

                Pen thinPen = new Pen(Brushes.DarkGray, 1.0);
                thinPen.StartLineCap = PenLineCap.Round;
                thinPen.EndLineCap   = PenLineCap.Round;
                SimpleTransform transform = new SimpleTransform(semiWidth, semiHeight, this.Lissajous.ScaleFactor, this.Lissajous.ScaleFactor);
                var             center    = transform.Direct(new Point(0, 0));
                var             phase     = IsHorizontal ?
                                            this.lissajousPanel.TheGenerator.PhaseY() :
                                            this.lissajousPanel.TheGenerator.PhaseX() - Math.PI / 2;

                var amplitude = this.IsHorizontal ?
                                this.lissajousPanel.TheGenerator.AmplitudeY :
                                this.lissajousPanel.TheGenerator.AmplitudeX;

                var periphery = transform.Direct(
                    new Point(
                        amplitude * Math.Cos(phase),
                        amplitude * Math.Sin(phase)));

                double radius = this.Distance(center, periphery);

                dc.DrawEllipse(Brushes.Transparent, thinPen, center, radius, radius);
                dc.DrawLine(thinPen, center, periphery);
                if (this.IsHorizontal)
                {
                    dc.DrawLine(thinPen, periphery, new Point(0, periphery.Y));
                }
                else
                {
                    dc.DrawLine(thinPen, periphery, new Point(periphery.X, this.ActualHeight));
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Renders the horizontally moving composing sinusoid.
        /// </summary>
        /// <param name="dc">Graphics environment where to render.</param>
        /// <param name="toRender">Enumeration of points to render.</param>
        protected void RenderHorizontal(DrawingContext dc, IEnumerable <LissaPoint> toRender)
        {
            if (this.Lissajous == null)
            {
                return;
            }

            System.Diagnostics.Debug.WriteLine("toRender :" + toRender + " " + this.Lissajous);

            double semiHeight   = this.ActualHeight / 2;
            double scaleFactorX = this.ActualWidth / this.Lissajous.TheGenerator.DeltaTimeHeadTail;

            SimpleTransform transform = new SimpleTransform(0, semiHeight, -scaleFactorX, this.Lissajous.ScaleFactor);
            Pen             thinPen   = new Pen(Brushes.DarkGray, 1.0);

            thinPen.StartLineCap = PenLineCap.Round;
            thinPen.EndLineCap   = PenLineCap.Round;
            this.Render(transform, thinPen, dc, toRender, (point, startTime) => new Point(point.T - startTime, point.Y));
        }
Пример #5
0
        /// <summary>
        /// Renders the needed sinusoid.
        /// </summary>
        /// <param name="thinPen">Pen to be used.</param>
        /// <param name="dc">Graphics environment where to render.</param>
        /// <param name="toRender">Enumeration of points on the curve to render.</param>
        /// <param name="getPoint">Lambda returning the point to be shown on the composing sinusoid.</param>
        private void Render(SimpleTransform transform, Pen thinPen, DrawingContext dc, IEnumerable <LissaPoint> toRender, Func <LissaPoint, double, Point> getPoint)
        {
            bool   isFirst   = true;
            Point  lastPoint = new Point(0, 0);
            double startTime = 0;

            foreach (var point in toRender)
            {
                if (isFirst)
                {
                    startTime = point.T;
                }
                Point currentPoint = transform.Direct(getPoint(point, startTime));
                if (!isFirst)
                {
                    dc.DrawLine(thinPen, lastPoint, currentPoint);
                }

                lastPoint = currentPoint;
                isFirst   = false;
            }
        }