public override void fade(EasingTypes easing, int startTime, int endTime, double startOpacity, double endOpacity)
 {
     foreach (AbstractVisualGenerator obj in LayerGenerators)
     {
         obj.scale(easing, startTime, endTime, obj.Opacity * startOpacity, obj.Opacity * endOpacity);
     }
 }
 public override void move(EasingTypes easing, int startTime, int endTime, double startX, double startY, double endX, double endY)
 {
     foreach (AbstractVisualGenerator obj in LayerGenerators)
     {
         obj.move(easing, startTime, endTime, obj.X + startX, obj.Y + startY, obj.X + endX, obj.Y + endY);
     }
 }
 public override void scale(EasingTypes easing, int startTime, int endTime, double startScale, double endScale)
 {
     foreach (AbstractVisualGenerator obj in LayerGenerators)
     {
         obj.scale(easing, startTime, endTime, obj.Scale * startScale, obj.Scale * endScale);
     }
 }
 public override void color(EasingTypes easing, int startTime, int endTime, int startRed, int startGreen, int startBlue,
                   int endRed, int endGreen, int endBlue)
 {
     foreach (AbstractVisualGenerator obj in LayerGenerators)
     {
         obj.color(easing, startTime, endTime, Convert.ToInt32(obj.Red * (startRed / 255.0)), Convert.ToInt32(obj.Green * (startGreen / 255.0)), Convert.ToInt32(obj.Blue * (startBlue / 255.0)),
             Convert.ToInt32(obj.Red * (endRed / 255.0)), Convert.ToInt32(obj.Green * (endGreen / 255.0)), Convert.ToInt32(obj.Blue * (endBlue / 255.0)));
     }
 }
Example #5
0
        /// <summary>
        /// Cunstructor for normal storyboard commands
        /// </summary>
        /// <param name="easing"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="startParams"></param>
        /// <param name="endParams"></param>
        public Animation(AnimationType animationType, EasingTypes easing, int startTime, int endTime, double[] startParams,
                         double[] endParams)
            : base(startTime)
        {
            this.animationType = animationType;
            this.easing = easing;
            this.endTime = endTime;
            this.startParams = startParams;
            this.endParams = endParams;

            if (endTime < startTime)
                throw new CompilerException(-1, 404, animationType.ToString(), startTime.ToString(), endTime.ToString());
        }
Example #6
0
        public static Quaternion ValueAt(double time, Quaternion val1, Quaternion val2, double startTime, double endTime, EasingTypes easing = EasingTypes.None)
        {
            float current  = (float)(time - startTime);
            float duration = (float)(endTime - startTime);

            if (duration == 0 || current == 0)
            {
                return(val1);
            }

            return(Quaternion.Slerp(val1, val2, (float)ApplyEasing(easing, current, 0.0f, 1.0f, duration)));
        }
Example #7
0
        public static Color4 ValueAt(double time, Color4 startColour, Color4 endColour, double startTime, double endTime, EasingTypes easing = EasingTypes.None)
        {
            if (startColour == endColour)
            {
                return(startColour);
            }

            double current  = time - startTime;
            double duration = endTime - startTime;

            if (duration == 0 || current == 0)
            {
                return(startColour);
            }

            return(new Color4(
                       (float)Math.Max(0, Math.Min(1, ApplyEasing(easing, current, startColour.R, endColour.R - startColour.R, duration))),
                       (float)Math.Max(0, Math.Min(1, ApplyEasing(easing, current, startColour.G, endColour.G - startColour.G, duration))),
                       (float)Math.Max(0, Math.Min(1, ApplyEasing(easing, current, startColour.B, endColour.B - startColour.B, duration))),
                       (float)Math.Max(0, Math.Min(1, ApplyEasing(easing, current, startColour.A, endColour.A - startColour.A, duration)))));
        }
Example #8
0
 public Drawable MoveTo(Vector2 newPosition, double duration = 0, EasingTypes easing = EasingTypes.None)
 {
     updateTransformsOfType(typeof(TransformPosition));
     return(transformVectorTo(Position, newPosition, duration, easing, new TransformPosition(Clock)));
 }
 public SizeAnimator(NativeSize first, NativeSize last, int frames, EasingTypes easingType = EasingTypes.Linear, EasingModes easingMode = EasingModes.EaseIn)
     : base(first, last, frames, easingType, easingMode)
 {
 }
Example #10
0
 public Drawable RotateTo(float newRotation, double duration = 0, EasingTypes easing = EasingTypes.None)
 {
     updateTransformsOfType(typeof(TransformRotation));
     return(transformFloatTo(Rotation, newRotation, duration, easing, new TransformRotation(Clock)));
 }
Example #11
0
        private Drawable transformVectorTo(Vector2 startValue, Vector2 newValue, double duration, EasingTypes easing, TransformVector transform)
        {
            Type type = transform.GetType();

            if (transformationDelay == 0)
            {
                Transforms.RemoveAll(t => t.GetType() == type);

                if (startValue == newValue)
                {
                    return(this);
                }
            }
            else
            {
                startValue = (Transforms.FindLast(t => t.GetType() == type) as TransformVector)?.EndValue ?? startValue;
            }

            double startTime = Time + transformationDelay;

            transform.StartTime  = startTime;
            transform.EndTime    = startTime + duration;
            transform.StartValue = startValue;
            transform.EndValue   = newValue;
            transform.Easing     = easing;

            if (duration == 0)
            {
                transform.Apply(this);
            }
            else
            {
                Transforms.Add(transform);
            }

            return(this);
        }
Example #12
0
 /// <summary>
 /// Tweens the accent colour of a drawable to another colour.
 /// </summary>
 /// <param name="accentedDrawable">The drawable to apply the accent colour to.</param>
 /// <param name="newColour">The new accent colour.</param>
 /// <param name="duration">The tween duration.</param>
 /// <param name="easing">The tween easing.</param>
 public static void FadeAccent <T>(this T accentedDrawable, Color4 newColour, double duration = 0, EasingTypes easing = EasingTypes.None)
     where T : Transformable <Drawable>, IHasAccentColour
 {
     accentedDrawable.TransformTo(() => accentedDrawable.AccentColour, newColour, duration, easing, new TransformAccent());
 }
Example #13
0
 public Drawable FadeOut(double duration = 0, EasingTypes easing = EasingTypes.None)
 {
     return(FadeTo(0, duration, easing));
 }
Example #14
0
        public static Vector3 ValueAt(double time, Vector3 val1, Vector3 val2, double startTime, double endTime, EasingTypes easing = EasingTypes.None)
        {
            float current  = (float)(time - startTime);
            float duration = (float)(endTime - startTime);

            if (duration == 0 || current == 0)
            {
                return(val1);
            }

            return(new Vector3(
                       (float)ApplyEasing(easing, current, val1.X, val2.X - val1.X, duration),
                       (float)ApplyEasing(easing, current, val1.Y, val2.Y - val1.Y, duration),
                       (float)ApplyEasing(easing, current, val1.Z, val2.Z - val1.Z, duration)));
        }
Example #15
0
        public bool DelayedMovements; // ModManager.CheckActive(Mods.Relax2);

        private void createAutoReplay()
        {
            int buttonIndex = 0;

            EasingTypes preferredEasing = DelayedMovements ? EasingTypes.InOutCubic : EasingTypes.Out;

            addFrameToReplay(new LegacyReplayFrame(-100000, 256, 500, LegacyButtonState.None));
            addFrameToReplay(new LegacyReplayFrame(beatmap.HitObjects[0].StartTime - 1500, 256, 500, LegacyButtonState.None));
            addFrameToReplay(new LegacyReplayFrame(beatmap.HitObjects[0].StartTime - 1000, 256, 192, LegacyButtonState.None));

            // We are using ApplyModsToRate and not ApplyModsToTime to counteract the speed up / slow down from HalfTime / DoubleTime so that we remain at a constant framerate of 60 fps.
            float frameDelay = (float)applyModsToRate(1000.0 / 60.0);

            // Already superhuman, but still somewhat realistic
            int reactionTime = (int)applyModsToRate(100);


            for (int i = 0; i < beatmap.HitObjects.Count; i++)
            {
                OsuHitObject h = beatmap.HitObjects[i];

                //if (h.EndTime < InputManager.ReplayStartTime)
                //{
                //    h.IsHit = true;
                //    continue;
                //}

                int endDelay = h is Spinner ? 1 : 0;

                if (DelayedMovements && i > 0)
                {
                    OsuHitObject last = beatmap.HitObjects[i - 1];

                    double endTime = (last as IHasEndTime)?.EndTime ?? last.StartTime;

                    //Make the cursor stay at a hitObject as long as possible (mainly for autopilot).
                    if (h.StartTime - h.HitWindowFor(OsuScoreResult.Miss) > endTime + h.HitWindowFor(OsuScoreResult.Hit50) + 50)
                    {
                        if (!(last is Spinner) && h.StartTime - endTime < 1000)
                        {
                            addFrameToReplay(new LegacyReplayFrame(endTime + h.HitWindowFor(OsuScoreResult.Hit50), last.EndPosition.X, last.EndPosition.Y, LegacyButtonState.None));
                        }
                        if (!(h is Spinner))
                        {
                            addFrameToReplay(new LegacyReplayFrame(h.StartTime - h.HitWindowFor(OsuScoreResult.Miss), h.Position.X, h.Position.Y, LegacyButtonState.None));
                        }
                    }
                    else if (h.StartTime - h.HitWindowFor(OsuScoreResult.Hit50) > endTime + h.HitWindowFor(OsuScoreResult.Hit50) + 50)
                    {
                        if (!(last is Spinner) && h.StartTime - endTime < 1000)
                        {
                            addFrameToReplay(new LegacyReplayFrame(endTime + h.HitWindowFor(OsuScoreResult.Hit50), last.EndPosition.X, last.EndPosition.Y, LegacyButtonState.None));
                        }
                        if (!(h is Spinner))
                        {
                            addFrameToReplay(new LegacyReplayFrame(h.StartTime - h.HitWindowFor(OsuScoreResult.Hit50), h.Position.X, h.Position.Y, LegacyButtonState.None));
                        }
                    }
                    else if (h.StartTime - h.HitWindowFor(OsuScoreResult.Hit100) > endTime + h.HitWindowFor(OsuScoreResult.Hit100) + 50)
                    {
                        if (!(last is Spinner) && h.StartTime - endTime < 1000)
                        {
                            addFrameToReplay(new LegacyReplayFrame(endTime + h.HitWindowFor(OsuScoreResult.Hit100), last.EndPosition.X, last.EndPosition.Y, LegacyButtonState.None));
                        }
                        if (!(h is Spinner))
                        {
                            addFrameToReplay(new LegacyReplayFrame(h.StartTime - h.HitWindowFor(OsuScoreResult.Hit100), h.Position.X, h.Position.Y, LegacyButtonState.None));
                        }
                    }
                }


                Vector2     targetPosition   = h.Position;
                EasingTypes easing           = preferredEasing;
                float       spinnerDirection = -1;

                if (h is Spinner)
                {
                    targetPosition.X = Frames[Frames.Count - 1].MouseX;
                    targetPosition.Y = Frames[Frames.Count - 1].MouseY;

                    Vector2 difference = spinner_centre - targetPosition;

                    float differenceLength = difference.Length;
                    float newLength        = (float)Math.Sqrt(differenceLength * differenceLength - spin_radius * spin_radius);

                    if (differenceLength > spin_radius)
                    {
                        float angle = (float)Math.Asin(spin_radius / differenceLength);

                        if (angle > 0)
                        {
                            spinnerDirection = -1;
                        }
                        else
                        {
                            spinnerDirection = 1;
                        }

                        difference.X = difference.X * (float)Math.Cos(angle) - difference.Y * (float)Math.Sin(angle);
                        difference.Y = difference.X * (float)Math.Sin(angle) + difference.Y * (float)Math.Cos(angle);

                        difference.Normalize();
                        difference *= newLength;

                        targetPosition += difference;

                        easing = EasingTypes.In;
                    }
                    else if (difference.Length > 0)
                    {
                        targetPosition = spinner_centre - difference * (spin_radius / difference.Length);
                    }
                    else
                    {
                        targetPosition = spinner_centre + new Vector2(0, -spin_radius);
                    }
                }


                // Do some nice easing for cursor movements
                if (Frames.Count > 0)
                {
                    LegacyReplayFrame lastFrame = Frames[Frames.Count - 1];

                    // Wait until Auto could "see and react" to the next note.
                    double waitTime = h.StartTime - Math.Max(0.0, DrawableOsuHitObject.TIME_PREEMPT - reactionTime);
                    if (waitTime > lastFrame.Time)
                    {
                        lastFrame = new LegacyReplayFrame(waitTime, lastFrame.MouseX, lastFrame.MouseY, lastFrame.ButtonState);
                        addFrameToReplay(lastFrame);
                    }

                    Vector2 lastPosition = new Vector2(lastFrame.MouseX, lastFrame.MouseY);

                    double timeDifference = applyModsToTime(h.StartTime - lastFrame.Time);

                    // Only "snap" to hitcircles if they are far enough apart. As the time between hitcircles gets shorter the snapping threshold goes up.
                    if (timeDifference > 0 &&                                                                  // Sanity checks
                        ((lastPosition - targetPosition).Length > h.Radius * (1.5 + 100.0 / timeDifference) || // Either the distance is big enough
                         timeDifference >= 266))                                                               // ... or the beats are slow enough to tap anyway.
                    {
                        // Perform eased movement
                        for (double time = lastFrame.Time + frameDelay; time < h.StartTime; time += frameDelay)
                        {
                            Vector2 currentPosition = Interpolation.ValueAt(time, lastPosition, targetPosition, lastFrame.Time, h.StartTime, easing);
                            addFrameToReplay(new LegacyReplayFrame((int)time, currentPosition.X, currentPosition.Y, lastFrame.ButtonState));
                        }

                        buttonIndex = 0;
                    }
                    else
                    {
                        buttonIndex++;
                    }
                }

                LegacyButtonState button = buttonIndex % 2 == 0 ? LegacyButtonState.Left1 : LegacyButtonState.Right1;

                double hEndTime = (h as IHasEndTime)?.EndTime ?? h.StartTime;

                LegacyReplayFrame newFrame = new LegacyReplayFrame(h.StartTime, targetPosition.X, targetPosition.Y, button);
                LegacyReplayFrame endFrame = new LegacyReplayFrame(hEndTime + endDelay, h.EndPosition.X, h.EndPosition.Y, LegacyButtonState.None);

                // Decrement because we want the previous frame, not the next one
                int index = findInsertionIndex(newFrame) - 1;

                // Do we have a previous frame? No need to check for < replay.Count since we decremented!
                if (index >= 0)
                {
                    LegacyReplayFrame previousFrame = Frames[index];
                    var previousButton = previousFrame.ButtonState;

                    // If a button is already held, then we simply alternate
                    if (previousButton != LegacyButtonState.None)
                    {
                        Debug.Assert(previousButton != (LegacyButtonState.Left1 | LegacyButtonState.Right1));

                        // Force alternation if we have the same button. Otherwise we can just keep the naturally to us assigned button.
                        if (previousButton == button)
                        {
                            button = (LegacyButtonState.Left1 | LegacyButtonState.Right1) & ~button;
                            newFrame.SetButtonStates(button);
                        }

                        // We always follow the most recent slider / spinner, so remove any other frames that occur while it exists.
                        int endIndex = findInsertionIndex(endFrame);

                        if (index < Frames.Count - 1)
                        {
                            Frames.RemoveRange(index + 1, Math.Max(0, endIndex - (index + 1)));
                        }

                        // After alternating we need to keep holding the other button in the future rather than the previous one.
                        for (int j = index + 1; j < Frames.Count; ++j)
                        {
                            // Don't affect frames which stop pressing a button!
                            if (j < Frames.Count - 1 || Frames[j].ButtonState == previousButton)
                            {
                                Frames[j].SetButtonStates(button);
                            }
                        }
                    }
                }

                addFrameToReplay(newFrame);

                // We add intermediate frames for spinning / following a slider here.
                if (h is Spinner)
                {
                    Spinner s = h as Spinner;

                    Vector2 difference = targetPosition - spinner_centre;

                    float radius = difference.Length;
                    float angle  = radius == 0 ? 0 : (float)Math.Atan2(difference.Y, difference.X);

                    double t;

                    for (double j = h.StartTime + frameDelay; j < s.EndTime; j += frameDelay)
                    {
                        t = applyModsToTime(j - h.StartTime) * spinnerDirection;

                        Vector2 pos = spinner_centre + circlePosition(t / 20 + angle, spin_radius);
                        addFrameToReplay(new LegacyReplayFrame((int)j, pos.X, pos.Y, button));
                    }

                    t = applyModsToTime(s.EndTime - h.StartTime) * spinnerDirection;
                    Vector2 endPosition = spinner_centre + circlePosition(t / 20 + angle, spin_radius);

                    addFrameToReplay(new LegacyReplayFrame(s.EndTime, endPosition.X, endPosition.Y, button));

                    endFrame.MouseX = endPosition.X;
                    endFrame.MouseY = endPosition.Y;
                }
                else if (h is Slider)
                {
                    Slider s = h as Slider;

                    for (double j = frameDelay; j < s.Duration; j += frameDelay)
                    {
                        Vector2 pos = s.PositionAt(j / s.Duration);
                        addFrameToReplay(new LegacyReplayFrame(h.StartTime + j, pos.X, pos.Y, button));
                    }

                    addFrameToReplay(new LegacyReplayFrame(s.EndTime, s.EndPosition.X, s.EndPosition.Y, button));
                }

                // We only want to let go of our button if we are at the end of the current replay. Otherwise something is still going on after us so we need to keep the button pressed!
                if (Frames[Frames.Count - 1].Time <= endFrame.Time)
                {
                    addFrameToReplay(endFrame);
                }
            }

            //Player.currentScore.Replay = InputManager.ReplayScore.Replay;
            //Player.currentScore.PlayerName = "osu!";
        }
 public virtual void colorHsb(EasingTypes easing, int startTime, int endTime, double startHue, double startSaturation, double startBrightness, double endHue, double endSaturation, double endBrightness)
 {
     int startRed, startGreen, startBlue, endRed, endGreen, endBlue;
     ColorUtil.HsbToRgb(startHue, startSaturation, startBrightness, out startRed, out startGreen, out startBlue);
     ColorUtil.HsbToRgb(endHue, endSaturation, endBrightness, out endRed, out endGreen, out endBlue);
     color(easing, startTime, endTime, startRed, startGreen, startBlue,
                    endRed, endGreen, endBlue);
 }
 public virtual void fade(EasingTypes easing, int startTime, int endTime, double startOpacity, double endOpacity)
 {
     if (!Enum.IsDefined(typeof(EasingTypes), easing))
         throw new CompilerException(-1, 315, easing.ToString());
     var startParams = new[] { startOpacity };
     var endParams = new[] { endOpacity };
     AddCommand(new Animation(AnimationType.Fade, easing, startTime, endTime, startParams, endParams));
     opacity = endOpacity;
 }
 public virtual void moveY(EasingTypes easing, int startTime, int endTime, double startY, double endY)
 {
     if (!Enum.IsDefined(typeof(EasingTypes), easing))
         throw new CompilerException(-1, 315, easing.ToString());
     var startParams = new[] { startY };
     var endParams = new[] { endY };
     AddCommand(new Animation(AnimationType.MoveY, easing, startTime, endTime, startParams, endParams));
     this.y = (int)endY;
 }
        public virtual void scaleVec(EasingTypes easing, int startTime, int endTime, double startX, double startY, double endX,
							 double endY)
        {
            if (!Enum.IsDefined(typeof(EasingTypes), easing))
                throw new CompilerException(-1, 315, easing.ToString());
            var startParams = new[] { startX, startY };
            var endParams = new[] { endX, endY };
            AddCommand(new Animation(AnimationType.ScaleVec, easing, startTime, endTime, startParams, endParams));
            this.scaleFactor = (endX + endY) / 2;
        }
 public virtual void rotate(EasingTypes easing, int startTime, int endTime, double startAngle, double endAngle)
 {
     if (!Enum.IsDefined(typeof(EasingTypes), easing))
         throw new CompilerException(-1, 315, easing.ToString());
     var startParams = new[] { startAngle };
     var endParams = new[] { endAngle };
     AddCommand(new Animation(AnimationType.Rotate, easing, startTime, endTime, startParams, endParams));
     rotation = endAngle;
 }
 public void color(EasingTypes easing, int startTime, int endTime, 
                   System.Drawing.Color startColor, System.Drawing.Color endColor)
 {
     color(easing, startTime, endTime, startColor.R, startColor.G, startColor.B, endColor.R, endColor.G, endColor.B);
 }
 public void RotateTo(float newRotation, double duration = 0, EasingTypes easing = EasingTypes.None)
 {
     UpdateTransformsOfType(typeof(TransformRotation));
     TransformFloatTo(Rotation, newRotation, duration, easing, new TransformRotation());
 }
Example #23
0
 public void BlurTo(Vector2 sigma, double duration, EasingTypes easing = EasingTypes.None)
 {
     background?.BlurTo(sigma, duration, easing);
     blurTarget = sigma;
 }
 public void MoveToY(float destination, double duration = 0, EasingTypes easing = EasingTypes.None)
 {
     UpdateTransformsOfType(typeof(TransformPositionY));
     TransformFloatTo(Position.Y, destination, duration, easing, new TransformPositionY());
 }
Example #25
0
        void OnGUI()
        {
            GUILayout.BeginArea(new Rect(7, 0, this.position.width - 14, this.position.height));
            EditorGUI.BeginChangeCheck();
            GUILayout.Space(5);
            GUILayout.Label("Add easing to UI Animation", EditorStyles.boldLabel);

            detachable = EditorGUILayout.Toggle("Detachable", detachable, GUILayout.Height(20));
            if (GUI.changed)
            {
                EditorPrefs.SetBool("UIAnimationWindowDetachable", detachable);
                this.Close();
                UIAnimatorWindow.ShowWindow();
            }
            clip = EditorGUILayout.ObjectField("Animation Clip:", clip, typeof(AnimationClip), true, GUILayout.Height(16)) as AnimationClip;
            GUILayout.Space(5);
            if (clip == null)
            {
                EditorGUILayout.HelpBox("Select An Animation Clip!", MessageType.Info);
                valid = false;
                End();
                return;
            }
            //if the user changed the clip get the new bindings
            if (clip != oldclip)
            {
                refreshClipData(clip);
            }
            if (properties.Length > 0)
            {
                valid = true;
                //getting the selected Property from the user
                propertiesindex = EditorGUILayout.Popup("Property:", propertiesindex, displayableProperties, GUILayout.Height(25));
                propertyName    = properties[propertiesindex];

                originalCurve = EditorGUILayout.CurveField("Current Curve: ", curveByPropertyName(propertyName), Color.magenta, new Rect(), GUILayout.Height(windowWidth / 3));

                startkeyframe = EditorGUILayout.IntSlider("Start from Keyframe:", startkeyframe, 0, originalCurve.keys.Length - 1, GUILayout.Height(17));
                endkeyframe   = EditorGUILayout.IntSlider("End with Keyframe:", endkeyframe, 0, originalCurve.keys.Length - 1, GUILayout.Height(17));
                if (startkeyframe >= endkeyframe)
                {
                    EditorGUILayout.HelpBox("No Keyframes would be affected!", MessageType.Warning);
                    valid = false;
                }
                GUILayout.Space(5);
                GUILayout.Label("Easing:", EditorStyles.label);
                easeType = (EasingTypes)EditorGUILayout.EnumPopup(easeType, GUILayout.Height(18));
                GUILayout.Space(5);
                keyframes = EditorGUILayout.IntField("Number of Keyframes:", keyframes, GUILayout.Height(17));
                if (keyframes < 2)
                {
                    EditorGUILayout.HelpBox("At Least 2 Keyframes are needed!", MessageType.Error);
                    valid = false;
                }
                keyframeReductionTolerance = EditorGUILayout.FloatField("Reduction Tolerance:", keyframeReductionTolerance, GUILayout.Height(17));

                if (valid)
                {
                    proposedCurve = modifiedCurve(originalCurve);
                    //Showing the proposed Curve can cause the window to not draw until dragged when reopening.
                    proposedCurve = EditorGUILayout.CurveField("New Curve: ", proposedCurve, Color.green, new Rect(), GUILayout.Height(windowWidth / 3));
                }
            }
            else
            {
                EditorGUILayout.HelpBox("No Modifiable Curves on this Clip", MessageType.Warning);
            }
            if (valid)
            {
                if (GUILayout.Button("Modify Animation", GUILayout.Height(25)))
                {
                    applyModifications();
                }
            }
            End();
        }
        protected void TransformVectorTo(Vector2 startValue, Vector2 newValue, double duration, EasingTypes easing, TransformVector transform)
        {
            Type type = transform.GetType();

            if (transformationDelay == 0)
            {
                Transforms.RemoveAll(t => t.GetType() == type);

                if (startValue == newValue)
                {
                    return;
                }
            }
            else
            {
                startValue = (Transforms.FindLast(t => t.GetType() == type) as TransformVector)?.EndValue ?? startValue;
            }

            double startTime = Clock != null ? (Time.Current + transformationDelay) : 0;

            transform.StartTime  = startTime;
            transform.EndTime    = startTime + duration;
            transform.StartValue = startValue;
            transform.EndValue   = newValue;
            transform.Easing     = easing;

            if (Clock == null)
            {
                transform.UpdateTime(new FrameTimeInfo {
                    Current = transform.EndTime
                });
                transform.Apply(this);
            }
            else if (duration == 0 && transformationDelay == 0)
            {
                transform.UpdateTime(Time);
                transform.Apply(this);
            }
            else
            {
                Transforms.Add(transform);
            }
        }
Example #27
0
 public Drawable FadeTo(float newAlpha, double duration = 0, EasingTypes easing = EasingTypes.None)
 {
     updateTransformsOfType(typeof(TransformAlpha));
     return(transformFloatTo(Alpha, newAlpha, duration, easing, new TransformAlpha(Clock)));
 }
 public void ScaleTo(float newScale, double duration = 0, EasingTypes easing = EasingTypes.None)
 {
     UpdateTransformsOfType(typeof(TransformScale));
     TransformVectorTo(Scale, new Vector2(newScale), duration, easing, new TransformScale());
 }
Example #29
0
 public Drawable MoveToY(float destination, double duration = 0, EasingTypes easing = EasingTypes.None)
 {
     updateTransformsOfType(typeof(TransformPositionY));
     return(transformFloatTo(Position.Y, destination, duration, easing, new TransformPositionY(Clock)));
 }
 public void ResizeTo(Vector2 newSize, double duration = 0, EasingTypes easing = EasingTypes.None)
 {
     UpdateTransformsOfType(typeof(TransformSize));
     TransformVectorTo(Size, newSize, duration, easing, new TransformSize());
 }
Example #31
0
 public Drawable ScaleTo(Vector2 newScale, double duration = 0, EasingTypes easing = EasingTypes.None)
 {
     updateTransformsOfType(typeof(TransformScaleVector));
     return(transformVectorTo(Scale, newScale, duration, easing, new TransformScaleVector(Clock)));
 }
 public void MoveTo(Vector2 newPosition, double duration = 0, EasingTypes easing = EasingTypes.None)
 {
     UpdateTransformsOfType(typeof(TransformPosition));
     TransformVectorTo(Position, newPosition, duration, easing, new TransformPosition());
 }
Example #33
0
 public Drawable MoveToRelative(Vector2 offset, int duration = 0, EasingTypes easing = EasingTypes.None)
 {
     updateTransformsOfType(typeof(TransformPosition));
     return(MoveTo((Transforms.FindLast(t => t is TransformPosition) as TransformPosition)?.EndValue ?? Position + offset, duration, easing));
 }
 public void MoveToOffset(Vector2 offset, int duration = 0, EasingTypes easing = EasingTypes.None)
 {
     UpdateTransformsOfType(typeof(TransformPosition));
     MoveTo((Transforms.FindLast(t => t is TransformPosition) as TransformPosition)?.EndValue ?? Position + offset, duration, easing);
 }
Example #35
0
        public static RectangleF ValueAt(double time, RectangleF val1, RectangleF val2, double startTime, double endTime, EasingTypes easing = EasingTypes.None)
        {
            float current  = (float)(time - startTime);
            float duration = (float)(endTime - startTime);

            if (duration == 0 || current == 0)
            {
                return(val1);
            }

            return(new RectangleF(
                       (float)ApplyEasing(easing, current, val1.X, val2.X - val1.X, duration),
                       (float)ApplyEasing(easing, current, val1.Y, val2.Y - val1.Y, duration),
                       (float)ApplyEasing(easing, current, val1.Width, val2.Width - val1.Width, duration),
                       (float)ApplyEasing(easing, current, val1.Height, val2.Height - val1.Height, duration)));
        }
Example #36
0
 /// <summary>
 ///     初始化預設物件
 /// </summary>
 public virtual void InitialDefaultValue()
 {
     CurveEasingTypes = EasingTypes.InSine;
     ObjectType       = RpBaseObjectType.ObjectType.Undefined;
 }
Example #37
0
        public static double ApplyEasing(EasingTypes easing, double time, double initial, double change, double duration)
        {
            if (change == 0 || time == 0 || duration == 0)
            {
                return(initial);
            }
            if (time == duration)
            {
                return(initial + change);
            }

            switch (easing)
            {
            default:
                return(change * (time / duration) + initial);

            case EasingTypes.In:
            case EasingTypes.InQuad:
                return(change * (time /= duration) * time + initial);

            case EasingTypes.Out:
            case EasingTypes.OutQuad:
                return(-change * (time /= duration) * (time - 2) + initial);

            case EasingTypes.InOutQuad:
                if ((time /= duration / 2) < 1)
                {
                    return(change / 2 * time * time + initial);
                }
                return(-change / 2 * ((--time) * (time - 2) - 1) + initial);

            case EasingTypes.InCubic:
                return(change * (time /= duration) * time * time + initial);

            case EasingTypes.OutCubic:
                return(change * ((time = time / duration - 1) * time * time + 1) + initial);

            case EasingTypes.InOutCubic:
                if ((time /= duration / 2) < 1)
                {
                    return(change / 2 * time * time * time + initial);
                }
                return(change / 2 * ((time -= 2) * time * time + 2) + initial);

            case EasingTypes.InQuart:
                return(change * (time /= duration) * time * time * time + initial);

            case EasingTypes.OutQuart:
                return(-change * ((time = time / duration - 1) * time * time * time - 1) + initial);

            case EasingTypes.InOutQuart:
                if ((time /= duration / 2) < 1)
                {
                    return(change / 2 * time * time * time * time + initial);
                }
                return(-change / 2 * ((time -= 2) * time * time * time - 2) + initial);

            case EasingTypes.InQuint:
                return(change * (time /= duration) * time * time * time * time + initial);

            case EasingTypes.OutQuint:
                return(change * ((time = time / duration - 1) * time * time * time * time + 1) + initial);

            case EasingTypes.InOutQuint:
                if ((time /= duration / 2) < 1)
                {
                    return(change / 2 * time * time * time * time * time + initial);
                }
                return(change / 2 * ((time -= 2) * time * time * time * time + 2) + initial);

            case EasingTypes.InSine:
                return(-change *Math.Cos(time / duration *(MathHelper.Pi / 2)) + change + initial);

            case EasingTypes.OutSine:
                return(change * Math.Sin(time / duration * (MathHelper.Pi / 2)) + initial);

            case EasingTypes.InOutSine:
                return(-change / 2 * (Math.Cos(MathHelper.Pi * time / duration) - 1) + initial);

            case EasingTypes.InExpo:
                return(change * Math.Pow(2, 10 * (time / duration - 1)) + initial);

            case EasingTypes.OutExpo:
                return((time == duration) ? initial + change : change *(-Math.Pow(2, -10 * time / duration) + 1) + initial);

            case EasingTypes.InOutExpo:
                if ((time /= duration / 2) < 1)
                {
                    return(change / 2 * Math.Pow(2, 10 * (time - 1)) + initial);
                }
                return(change / 2 * (-Math.Pow(2, -10 * --time) + 2) + initial);

            case EasingTypes.InCirc:
                return(-change * (Math.Sqrt(1 - (time /= duration) * time) - 1) + initial);

            case EasingTypes.OutCirc:
                return(change * Math.Sqrt(1 - (time = time / duration - 1) * time) + initial);

            case EasingTypes.InOutCirc:
                if ((time /= duration / 2) < 1)
                {
                    return(-change / 2 * (Math.Sqrt(1 - time * time) - 1) + initial);
                }
                return(change / 2 * (Math.Sqrt(1 - (time -= 2) * time) + 1) + initial);

            case EasingTypes.InElastic:
            {
                if ((time /= duration) == 1)
                {
                    return(initial + change);
                }

                var    p = duration * .3;
                var    a = change;
                double s;
                if (a < Math.Abs(change))
                {
                    a = change;
                    s = p / 4;
                }
                else
                {
                    s = p / (2 * MathHelper.Pi) * Math.Asin(change / a);
                }
                return(-(a * Math.Pow(2, 10 * (time -= 1)) * Math.Sin((time * duration - s) * (2 * MathHelper.Pi) / p)) + initial);
            }

            case EasingTypes.OutElastic:
            {
                if ((time /= duration) == 1)
                {
                    return(initial + change);
                }

                var    p = duration * .3;
                var    a = change;
                double s;
                if (a < Math.Abs(change))
                {
                    a = change;
                    s = p / 4;
                }
                else
                {
                    s = p / (2 * MathHelper.Pi) * Math.Asin(change / a);
                }
                return(a * Math.Pow(2, -10 * time) * Math.Sin((time * duration - s) * (2 * MathHelper.Pi) / p) + change + initial);
            }

            case EasingTypes.OutElasticHalf:
            {
                if ((time /= duration) == 1)
                {
                    return(initial + change);
                }

                var    p = duration * .3;
                var    a = change;
                double s;
                if (a < Math.Abs(change))
                {
                    a = change;
                    s = p / 4;
                }
                else
                {
                    s = p / (2 * MathHelper.Pi) * Math.Asin(change / a);
                }
                return(a * Math.Pow(2, -10 * time) * Math.Sin((0.5f * time * duration - s) * (2 * MathHelper.Pi) / p) + change + initial);
            }

            case EasingTypes.OutElasticQuarter:
            {
                if ((time /= duration) == 1)
                {
                    return(initial + change);
                }

                var    p = duration * .3;
                var    a = change;
                double s;
                if (a < Math.Abs(change))
                {
                    a = change;
                    s = p / 4;
                }
                else
                {
                    s = p / (2 * MathHelper.Pi) * Math.Asin(change / a);
                }
                return(a * Math.Pow(2, -10 * time) * Math.Sin((0.25f * time * duration - s) * (2 * MathHelper.Pi) / p) + change + initial);
            }

            case EasingTypes.InOutElastic:
            {
                if ((time /= duration / 2) == 2)
                {
                    return(initial + change);
                }

                var    p = duration * (.3 * 1.5);
                var    a = change;
                double s;
                if (a < Math.Abs(change))
                {
                    a = change;
                    s = p / 4;
                }
                else
                {
                    s = p / (2 * MathHelper.Pi) * Math.Asin(change / a);
                }
                if (time < 1)
                {
                    return(-.5 * (a * Math.Pow(2, 10 * (time -= 1)) * Math.Sin((time * duration - s) * (2 * MathHelper.Pi) / p)) + initial);
                }
                return(a * Math.Pow(2, -10 * (time -= 1)) * Math.Sin((time * duration - s) * (2 * MathHelper.Pi) / p) * .5 + change + initial);
            }

            case EasingTypes.InBack:
            {
                var s = 1.70158;
                return(change * (time /= duration) * time * ((s + 1) * time - s) + initial);
            }

            case EasingTypes.OutBack:
            {
                var s = 1.70158;
                return(change * ((time = time / duration - 1) * time * ((s + 1) * time + s) + 1) + initial);
            }

            case EasingTypes.InOutBack:
            {
                var s = 1.70158;
                if ((time /= duration / 2) < 1)
                {
                    return(change / 2 * (time * time * (((s *= 1.525) + 1) * time - s)) + initial);
                }
                return(change / 2 * ((time -= 2) * time * (((s *= 1.525) + 1) * time + s) + 2) + initial);
            }

            case EasingTypes.InBounce:
                return(change - ApplyEasing(EasingTypes.OutBounce, duration - time, 0, change, duration) + initial);

            case EasingTypes.OutBounce:
                if ((time /= duration) < 1 / 2.75)
                {
                    return(change * (7.5625 * time * time) + initial);
                }
                if (time < 2 / 2.75)
                {
                    return(change * (7.5625 * (time -= 1.5 / 2.75) * time + .75) + initial);
                }
                if (time < 2.5 / 2.75)
                {
                    return(change * (7.5625 * (time -= 2.25 / 2.75) * time + .9375) + initial);
                }
                return(change * (7.5625 * (time -= 2.625 / 2.75) * time + .984375) + initial);

            case EasingTypes.InOutBounce:
                if (time < duration / 2)
                {
                    return(ApplyEasing(EasingTypes.InBounce, time * 2, 0, change, duration) * .5 + initial);
                }
                return(ApplyEasing(EasingTypes.OutBounce, time * 2 - duration, 0, change, duration) * .5 + change * .5 + initial);
            }
        }
Example #38
0
        /// <summary>
        ///     Function returns an easing Function according to the given enum EasingTypes
        /// </summary>
        /// <param name="type">Type.</param>
        public static Func <float, float, float, float> Function(EasingTypes type)
        {
            switch (type)
            {
            case EasingTypes.Linear:
                return(Linear);

            case EasingTypes.QuadraticIn:
                return(QuadraticIn);

            case EasingTypes.QuadraticOut:
                return(QuadraticOut);

            case EasingTypes.QuadraticInOut:
                return(QuadraticInOut);

            case EasingTypes.QuarticIn:
                return(QuarticIn);

            case EasingTypes.QuarticOut:
                return(QuarticOut);

            case EasingTypes.QuarticInOut:
                return(QuarticInOut);

            case EasingTypes.QuinticIn:
                return(QuinticIn);

            case EasingTypes.QuinticOut:
                return(QuinticOut);

            case EasingTypes.QuinticInOut:
                return(QuinticInOut);

            case EasingTypes.CubicIn:
                return(CubicIn);

            case EasingTypes.CubicOut:
                return(CubicOut);

            case EasingTypes.CubicInOut:
                return(CubicInOut);

            case EasingTypes.ExponentialIn:
                return(ExponentialIn);

            case EasingTypes.ExponentialOut:
                return(ExponentialOut);

            case EasingTypes.ExponentialInOut:
                return(ExponentialInOut);

            case EasingTypes.CircularIn:
                return(CircularIn);

            case EasingTypes.CircularOut:
                return(CircularOut);

            case EasingTypes.CircularInOut:
                return(CircularInOut);

            case EasingTypes.SinusoidalIn:
                return(SinusoidalIn);

            case EasingTypes.SinusoidalOut:
                return(SinusoidalOut);

            case EasingTypes.SinusoidalInOut:
                return(SinusoidalInOut);

            case EasingTypes.ElasticIn:
                return(ElasticIn);

            case EasingTypes.ElasticOut:
                return(ElasticOut);

            case EasingTypes.ElasticInOut:
                return(ElasticInOut);

            case EasingTypes.BounceIn:
                return(BounceIn);

            case EasingTypes.BounceOut:
                return(BounceOut);

            case EasingTypes.BounceInOut:
                return(BounceInOut);

            case EasingTypes.BackIn:
                return(BackIn);

            case EasingTypes.BackOut:
                return(BackOut);

            case EasingTypes.BackInOut:
                return(BackInOut);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #39
0
        public static float ValueAt(double time, float val1, float val2, double startTime, double endTime, EasingTypes easing = EasingTypes.None)
        {
            if (val1 == val2)
            {
                return(val1);
            }

            double current  = time - startTime;
            double duration = endTime - startTime;

            if (current == 0)
            {
                return(val1);
            }
            if (duration == 0)
            {
                return(val2);
            }

            return((float)ApplyEasing(easing, current, val1, val2 - val1, duration));
        }
Example #40
0
 public void TransformSpacingTo(float newAlpha, double duration = 0, EasingTypes easing = EasingTypes.None)
 {
     UpdateTransformsOfType(typeof(TransformSpacing));
     TransformFloatTo(EdgeEffect.Colour.Linear.A, newAlpha, duration, easing, new TransformSpacing());
 }
Example #41
0
        public static int Main()
        {
            // Initialization
            //--------------------------------------------------------------------------------------
            const int screenWidth  = 800;
            const int screenHeight = 450;

            InitWindow(screenWidth, screenHeight, "raylib [easings] example - easings testbed");

            Vector2 ballPosition = new Vector2(100.0f, 200.0f);

            float t        = 0.0f;                         // Current time (in any unit measure, but same unit as duration)
            float d        = 300.0f;                       // Total time it should take to complete (duration)
            bool  paused   = true;
            bool  boundedT = true;                         // If true, t will stop when d >= td, otherwise t will keep adding td to its value every loop

            EasingTypes easingX = EasingTypes.EASING_NONE; // Easing selected for x axis
            EasingTypes easingY = EasingTypes.EASING_NONE; // Easing selected for y axis

            SetTargetFPS(60);
            //--------------------------------------------------------------------------------------

            // Main game loop
            while (!WindowShouldClose())    // Detect window close button or ESC key
            {
                // Update
                //----------------------------------------------------------------------------------
                if (IsKeyPressed(KEY_T))
                {
                    boundedT = !boundedT;
                }

                // Choose easing for the X axis
                if (IsKeyPressed(KEY_RIGHT))
                {
                    easingX++;

                    if (easingX > EasingTypes.EASING_NONE)
                    {
                        easingX = 0;
                    }
                }
                else if (IsKeyPressed(KEY_LEFT))
                {
                    if (easingX == 0)
                    {
                        easingX = EasingTypes.EASING_NONE;
                    }
                    else
                    {
                        easingX--;
                    }
                }

                // Choose easing for the Y axis
                if (IsKeyPressed(KEY_DOWN))
                {
                    easingY++;

                    if (easingY > EasingTypes.EASING_NONE)
                    {
                        easingY = 0;
                    }
                }
                else if (IsKeyPressed(KEY_UP))
                {
                    if (easingY == 0)
                    {
                        easingY = EasingTypes.EASING_NONE;
                    }
                    else
                    {
                        easingY--;
                    }
                }

                // Change d (duration) value
                if (IsKeyPressed(KEY_W) && d < D_MAX - D_STEP)
                {
                    d += D_STEP;
                }
                else if (IsKeyPressed(KEY_Q) && d > D_MIN + D_STEP)
                {
                    d -= D_STEP;
                }

                if (IsKeyDown(KEY_S) && d < D_MAX - D_STEP_FINE)
                {
                    d += D_STEP_FINE;
                }
                else if (IsKeyDown(KEY_A) && d > D_MIN + D_STEP_FINE)
                {
                    d -= D_STEP_FINE;
                }

                // Play, pause and restart controls
                if (IsKeyPressed(KEY_SPACE) || IsKeyPressed(KEY_T) ||
                    IsKeyPressed(KEY_RIGHT) || IsKeyPressed(KEY_LEFT) ||
                    IsKeyPressed(KEY_DOWN) || IsKeyPressed(KEY_UP) ||
                    IsKeyPressed(KEY_W) || IsKeyPressed(KEY_Q) ||
                    IsKeyDown(KEY_S) || IsKeyDown(KEY_A) ||
                    (IsKeyPressed(KEY_ENTER) && (boundedT == true) && (t >= d)))
                {
                    t = 0.0f;
                    ballPosition.x = 100.0f;
                    ballPosition.y = 100.0f;
                    paused         = true;
                }

                if (IsKeyPressed(KEY_ENTER))
                {
                    paused = !paused;
                }

                // Movement computation
                if (!paused && ((boundedT && t < d) || !boundedT))
                {
                    ballPosition.x = easings[(int)easingX].func(t, 100.0f, 700.0f - 100.0f, d);
                    ballPosition.y = easings[(int)easingY].func(t, 100.0f, 400.0f - 100.0f, d);
                    t += 1.0f;
                }
                //----------------------------------------------------------------------------------

                // Draw
                //----------------------------------------------------------------------------------
                BeginDrawing();

                ClearBackground(RAYWHITE);

                // Draw information text
                DrawText(string.Format("Easing x: {0}", easings[(int)easingX].name), 0, FONT_SIZE * 2, FONT_SIZE, LIGHTGRAY);
                DrawText(string.Format("Easing y: {0}", easings[(int)easingY].name), 0, FONT_SIZE * 3, FONT_SIZE, LIGHTGRAY);
                DrawText(string.Format("t ({0}) = {1:0.##} d = {2:0.##}", (boundedT == true) ? 'b' : 'u', t, d), 0, FONT_SIZE * 4, FONT_SIZE, LIGHTGRAY);

                // Draw instructions text
                DrawText("Use ENTER to play or pause movement, use SPACE to restart", 0, GetScreenHeight() - FONT_SIZE * 2, FONT_SIZE, LIGHTGRAY);
                DrawText("Use D and W or A and S keys to change duration", 0, GetScreenHeight() - FONT_SIZE * 3, FONT_SIZE, LIGHTGRAY);
                DrawText("Use LEFT or RIGHT keys to choose easing for the x axis", 0, GetScreenHeight() - FONT_SIZE * 4, FONT_SIZE, LIGHTGRAY);
                DrawText("Use UP or DOWN keys to choose easing for the y axis", 0, GetScreenHeight() - FONT_SIZE * 5, FONT_SIZE, LIGHTGRAY);

                // Draw ball
                DrawCircleV(ballPosition, 16.0f, MAROON);

                EndDrawing();
                //----------------------------------------------------------------------------------
            }

            // De-Initialization
            //--------------------------------------------------------------------------------------
            CloseWindow();
            //--------------------------------------------------------------------------------------

            return(0);
        }
        public virtual void color(EasingTypes easing, int startTime, int endTime, int startRed, int startGreen, int startBlue,
						  int endRed, int endGreen, int endBlue)
        {
            if (!Enum.IsDefined(typeof(EasingTypes), easing))
                throw new CompilerException(-1, 315, easing.ToString());
            var startParams = new double[] { startRed, startGreen, startBlue };
            var endParams = new double[] { endRed, endGreen, endBlue };
            AddCommand(new Animation(AnimationType.Color, easing, startTime, endTime, startParams, endParams));
            red = endRed;
            green = endGreen;
            blue = endBlue;
        }