コード例 #1
0
        public static ColorAnimationUsingKeyFrames FreeAnimation(Color startColor)
        {
            // mutued from XAML example at https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Media.Animation.ColorAnimation

            var linearColorKeyFrame = new LinearColorKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(2000)),
                Value   = Colors.Red
            };
            var discreteColorKeyFrame = new DiscreteColorKeyFrame
            {
                KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(2500)),
                Value   = Colors.Yellow
            };
            var splineColorKeyFrame = new SplineColorKeyFrame
            {
                KeyTime   = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(4500)),
                Value     = startColor,
                KeySpline = new KeySpline {
                    ControlPoint1 = new Point(0.6, 0.0), ControlPoint2 = new Point(0.9, 0.0)
                }
            };

            var colorAnimationUsingKeyFrames = new ColorAnimationUsingKeyFrames();
            ColorKeyFrameCollection colorKeyFrameCollection = colorAnimationUsingKeyFrames.KeyFrames;

            colorKeyFrameCollection.Add(linearColorKeyFrame);
            colorKeyFrameCollection.Add(discreteColorKeyFrame);
            colorKeyFrameCollection.Add(splineColorKeyFrame);

            return(colorAnimationUsingKeyFrames);
        }
コード例 #2
0
        private static ColorKeyFrame CreateColorKeyFrmas(KeyFrames <Color> Model)
        {
            ColorKeyFrame frame = null;

            switch (Model.Type)
            {
            case KeyFramesType.Spline: frame = new SplineColorKeyFrame()
            {
                    KeySpline = Model.Spline
            }; break;

            case KeyFramesType.Linear: frame = new LinearColorKeyFrame(); break;

            case KeyFramesType.Easing: frame = new EasingColorKeyFrame()
            {
                    EasingFunction = Model.EasingFunction
            }; break;

            case KeyFramesType.Discrete: frame = new DiscreteColorKeyFrame(); break;

            default: break;
            }
            frame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Model.KeyTime));
            frame.Value   = Model.Value;
            return(frame);
        }
コード例 #3
0
        /// <summary>
        /// In order to ripple the value up we claculate the time
        /// to on for each block
        /// </summary>
        private void SetTimerDelay()
        {
            for (int i = 0; i < NumberOfLeds; i++)
            {
                this.SetLedColours(i);

                double time = ((double)NumberOfLeds - i) / (double)NumberOfLeds;

                int endMs   = (int)(100 * time);
                int startMs = (int)(100 * (time - (1 / (double)NumberOfLeds)));

                SplineColorKeyFrame start = LayoutRoot.FindName("_startColour" + i) as SplineColorKeyFrame;
                SplineColorKeyFrame end   = LayoutRoot.FindName("_endColour" + i) as SplineColorKeyFrame;
                if (end != null && start != null)
                {
                    start.SetValue(SplineColorKeyFrame.KeyTimeProperty, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, startMs)));
                    end.SetValue(SplineColorKeyFrame.KeyTimeProperty, KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0, 0, endMs)));
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Sets the color according to On or off of a single LED
        /// </summary>
        /// <param name="i">The index of he led to set the color for</param>
        private void SetLedColours(int i)
        {
            SplineColorKeyFrame start = LayoutRoot.FindName("_startColour" + i) as SplineColorKeyFrame;

            if (start != null)
            {
                start.Value = this.LedOffColor;
            }

            SplineColorKeyFrame end = LayoutRoot.FindName("_endColour" + i) as SplineColorKeyFrame;

            if (end != null)
            {
                end.Value = this.LedOnColor;
            }

            Rectangle led = LayoutRoot.FindName("_led" + i) as Rectangle;

            if (led != null)
            {
                led.Stroke = this.MeterBorderBrush;
                led.Fill   = this.LedOffBrush;
            }
        }