Пример #1
0
        /// <summary>
        /// 绘制指定的 easing 的曲线图
        /// </summary>
        private void DrawEasingGraph(EasingFunctionBase easingFunction)
        {
            graph.Children.Clear();

            Path         path         = new Path();
            PathGeometry pathGeometry = new PathGeometry();
            PathFigure   pathFigure   = new PathFigure()
            {
                StartPoint = new Point(0, 0)
            };
            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

            // 0 - 1 之间每隔 0.005 计算出一段 LineSegment,用于显示此 0.005 时间段内的缓动曲线
            for (double i = 0; i < 1; i += 0.005)
            {
                double x = i * graphContainer.Width;
                double y = easingFunction.Ease(i) * graphContainer.Height;

                LineSegment segment = new LineSegment();
                segment.Point = new Point(x, y);
                pathSegmentCollection.Add(segment);
            }

            pathFigure.Segments = pathSegmentCollection;
            pathGeometry.Figures.Add(pathFigure);
            path.Data            = pathGeometry;
            path.Stroke          = new SolidColorBrush(Colors.Black);
            path.StrokeThickness = 1;

            graph.Children.Add(path);
        }
Пример #2
0
        public void Draw(EasingFunctionBase easingFunction)
        {
            canvas1.Children.Clear();


            PathSegmentCollection pathSegments = new PathSegmentCollection();

            for (double i = 0; i < 1; i += _samplingInterval)
            {
                double x = i * canvas1.Width;
                double y = easingFunction.Ease(i) * canvas1.Height;

                var segment = new LineSegment();
                segment.Point = new Point(x, y);

                pathSegments.Add(segment);
            }
            var p = new Path();

            p.Stroke          = new SolidColorBrush(Colors.Black);
            p.StrokeThickness = 3;
            PathFigureCollection figures = new PathFigureCollection();

            figures.Add(new PathFigure()
            {
                Segments = pathSegments
            });
            p.Data = new PathGeometry()
            {
                Figures = figures
            };
            canvas1.Children.Add(p);
        }
Пример #3
0
        public override object GetCurrentValue(
            object defaultOriginValue, object defaultDestinationValue,
            AnimationClock animationClock)
        {
            if (animationClock.CurrentProgress == null)
            {
                return(null);
            }

            double progress = animationClock.CurrentProgress.Value;

            if (Easing != null)
            {
                progress = Easing.Ease(progress);
            }

            Matrix from = From ?? (Matrix)defaultOriginValue;

            if (To.HasValue)
            {
                Matrix to        = To.Value;
                Matrix newMatrix = new Matrix(((to.M11 - from.M11) * progress) + from.M11, 0, 0, ((to.M22 - from.M22) * progress) + from.M22,
                                              ((to.OffsetX - from.OffsetX) * progress) + from.OffsetX, ((to.OffsetY - from.OffsetY) * progress) + from.OffsetY);
                return(newMatrix);
            }

            return(Matrix.Identity);
        }
Пример #4
0
        // Plots a graph of the passed easing function using the given sampling interval on the "Graph" Canvas control
        private void PlotEasingFunctionGraph(EasingFunctionBase easingFunction, double samplingInterval)
        {
            UISettings UserSettings = new UISettings();

            Graph.Children.Clear();

            Path         path         = new Path();
            PathGeometry pathGeometry = new PathGeometry();
            PathFigure   pathFigure   = new PathFigure()
            {
                StartPoint = new Point(0, 0)
            };
            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

            // Note that an easing function is just like a regular function that operates on doubles.
            // Here we plot the range of the easing function's output on the y-axis of a graph.
            for (double i = 0; i < 1; i += samplingInterval)
            {
                double x = i * GraphContainer.Width;
                double y = easingFunction.Ease(i) * GraphContainer.Height;

                LineSegment segment = new LineSegment();
                segment.Point = new Point(x, y);
                pathSegmentCollection.Add(segment);
            }

            pathFigure.Segments = pathSegmentCollection;
            pathGeometry.Figures.Add(pathFigure);
            path.Data            = pathGeometry;
            path.Stroke          = new SolidColorBrush(UserSettings.UIElementColor(UIElementType.ButtonText));
            path.StrokeThickness = 1;

            // Add the path to the Canvas
            Graph.Children.Add(path);
        }
        internal void Pulse(TimeSpan time)
        {
            if (_startTime.Ticks == 0)
            {
                _startTime = time;
                _onStart?.Invoke();
                return;
            }
            var elapsed = time - _startTime;

            if (IsPaused)
            {
                _startTime += elapsed;
            }
            else
            {
                var totalDuration = AutoReverse ? _duration.Add(_duration) : _duration;
                while (elapsed > totalDuration && IsRepeat)
                {
                    _startTime = time - (elapsed - totalDuration);
                    elapsed    = time - _startTime;
                }
                if (elapsed > totalDuration)
                {
                    _onEnd?.Invoke();
                    _tcs?.TrySetResult(true);
                    Dispose();
                }
                else
                {
                    double normalizedTime;
                    if (!AutoReverse || elapsed < _duration)
                    {
                        normalizedTime = elapsed.TotalMilliseconds / _duration.TotalMilliseconds;
                    }
                    else
                    {
                        normalizedTime = 1 - (elapsed - _duration).TotalMilliseconds / _duration.TotalMilliseconds;
                    }
                    if (_easing == null)
                    {
                        _easing = new QuadraticEase()
                        {
                            EasingMode = EasingMode.EaseInOut
                        }
                    }
                    ;
                    //if (_easing != null)
                    normalizedTime = _easing.Ease(normalizedTime);
                    _onPulse?.Invoke(normalizedTime);
                }
            }
        }
Пример #6
0
        private void DrawNewGraph()
        {
            polyline.Points.Clear();
            if (easingFunction == null)
            {
                polyline.Points.Add(new Point(0, 0));
                polyline.Points.Add(new Point(1000, 500));
                return;
            }

            for (decimal t = 0; t <= 1; t += 0.01m)
            {
                double x = (double)(1000 * t);
                double y = 500 * easingFunction.Ease((double)t);
                polyline.Points.Add(new Point(x, y));
            }
        }
Пример #7
0
        //Add Time
        private void AddTime(double delta)
        {
            if (useCurrentFrom_ && !isSetCurrentFrom_)
            {
                isSetCurrentFrom_ = true;
                from_             = 0;
                if (properties_.Length > 0)
                {
                    Type         t = target_.GetType();
                    PropertyInfo p = t.GetRuntimeProperty(properties_[0]);
                    if (p != null)
                    {
                        from_ = Convert.ToDouble(p.GetValue(target_));
                    }
                }
            }

            currentTime_ += delta;
            currentTime_  = Math.Min(duration_ + delay_, currentTime_);
            if (currentTime_ > delay_)
            {
                double diffSize  = to_ - from_;
                double timeScale = Math.Min(Math.Max((currentTime_ - delay_) / duration_, 0), 1);
                double currentValue;
                if (easeFunction_ == null)
                {
                    currentValue = timeScale * diffSize + from_;
                }
                else
                {
                    currentValue = easeFunction_.Ease(timeScale) * diffSize + from_;
                }

                Type t = target_.GetType();
                foreach (string property in properties_)
                {
                    PropertyInfo p = t.GetRuntimeProperty(property);
                    if (p != null && p.CanWrite)
                    {
                        p.SetValue(target_, currentValue);
                    }
                }
            }
        }
        private void DrawEaseCurvePath(EasingFunctionBase ease)
        {
            PathGeometry geometry = new PathGeometry();

            _curvePath.Data = geometry;
            PathFigure figure = new PathFigure();

            figure.StartPoint = new Point(0.0, 100.0);
            geometry.Figures.Add(figure);
            double resolution = 2000;

            for (int i = 0; i <= resolution; i++)
            {
                double      d       = ease.Ease(i / resolution);
                LineSegment segment = new LineSegment();
                segment.Point = new Point(i * 100 / resolution, 100.0 - (d * 100.0));
                figure.Segments.Add(segment);
            }
        }
 protected override double EaseInCore(double normalizedTime)
 {
     return(1d - _baseFunction?.Ease(1d - normalizedTime) ?? normalizedTime);
 }