public static async Task AnimateAsync(this IRectangularF rectangular, RectangularAnimationOptions options) { var startX = rectangular.Left; var startY = rectangular.Top; var startW = rectangular.Width; var startH = rectangular.Height; await Animator.AnimateAsync(new FloatAnimatorOptions() { Duration = options.Duration, AutoReverse = options.AutoReverse, AutoReverseDelay = options.AutoReverseDelay, DelayProvider = options.DelayProvider, Loop = options.Loop, EasingFunction = options.EasingFunction, From = 0, To = 1, IsCancelled = options.IsCancelled, Setter = v => { var dest = options.Destination(); var xDelta = dest.Left - startX; var yDelta = dest.Top - startY; var wDelta = dest.Width - startW; var hDelta = dest.Height - startH; var frameX = startX + (v *xDelta); var frameY = startY + (v *yDelta); var frameW = startW + (v *wDelta); var frameH = startH + (v *hDelta); var frameBounds = RectangularF.Create(frameX, frameY, frameW, frameH); options.Setter(rectangular, frameBounds); } }); }
public async Task TestAnimatorInTimeAsync() { var app = new CliTestHarness(TestContext, 40, 1, true); var delayProvider = new KeyframeDelayProvider(app); app.InvokeNextCycle(() => { var panel = app.LayoutRoot.Add(new SpaceTimePanel(40, 1)); panel.SpaceTime.Start(); app.SecondsBetweenKeyframes = panel.SpaceTime.Increment.TotalSeconds; panel.SpaceTime.Invoke(async() => { panel.RealTimeViewing.Enabled = false; var element = panel.SpaceTime.Add(new SpacialElement()); element.ResizeTo(1, 1); await app.PaintAndRecordKeyFrameAsync(); await Animator.AnimateAsync(new FloatAnimatorOptions() { From = 0, To = panel.Width - 1, Duration = 3000, Setter = v => element.MoveTo(v, element.Top), DelayProvider = delayProvider, AutoReverse = true, AutoReverseDelay = 1000, }); panel.SpaceTime.Stop(); app.Stop(); }); }); await app.Start(); app.AssertThisTestMatchesLKG(); Console.WriteLine(delayProvider.DelayCount + " delays"); Console.WriteLine(app.TotalPaints + " paints"); Console.WriteLine(app.TotalCycles + " cycles"); }
public static Task AnimateAsync(RGBAnimationOptions options) { var deltaBufferR = new float[options.Transitions.Count]; var deltaBufferG = new float[options.Transitions.Count]; var deltaBufferB = new float[options.Transitions.Count]; var deltaBufferRReversed = new float[options.Transitions.Count]; var deltaBufferGReversed = new float[options.Transitions.Count]; var deltaBufferBReversed = new float[options.Transitions.Count]; for (var i = 0; i < options.Transitions.Count; i++) { deltaBufferR[i] = options.Transitions[i].Value.R - options.Transitions[i].Key.R; deltaBufferG[i] = options.Transitions[i].Value.G - options.Transitions[i].Key.G; deltaBufferB[i] = options.Transitions[i].Value.B - options.Transitions[i].Key.B; deltaBufferRReversed[i] = options.Transitions[i].Key.R - options.Transitions[i].Value.R; deltaBufferGReversed[i] = options.Transitions[i].Key.G - options.Transitions[i].Value.G; deltaBufferBReversed[i] = options.Transitions[i].Key.B - options.Transitions[i].Value.B; } var colorBuffer = new RGB[options.Transitions.Count]; var isReversed = false; return(Animator.AnimateAsync(new FloatAnimatorOptions() { From = 0, To = 1, Duration = options.Duration, AutoReverse = options.AutoReverse, AutoReverseDelay = options.AutoReverseDelay, DelayProvider = options.DelayProvider, EasingFunction = options.EasingFunction, IsCancelled = options.IsCancelled, Loop = options.Loop, OnReversedChanged = (r) => isReversed = r, Setter = percentage => { if (isReversed == false) { for (var i = 0; i < options.Transitions.Count; i++) { if (percentage == 1) { colorBuffer[i] = new RGB( (byte)(options.Transitions[i].Value.R), (byte)(options.Transitions[i].Value.G), (byte)(options.Transitions[i].Value.B)); } else { var rDeltaFrame = deltaBufferR[i] * percentage; var gDeltaFrame = deltaBufferG[i] * percentage; var bDeltaFrame = deltaBufferB[i] * percentage; colorBuffer[i] = new RGB( (byte)(options.Transitions[i].Key.R + rDeltaFrame), (byte)(options.Transitions[i].Key.G + gDeltaFrame), (byte)(options.Transitions[i].Key.B + bDeltaFrame)); } } } else { percentage = 1 - percentage; for (var i = 0; i < options.Transitions.Count; i++) { var rDeltaFrame = deltaBufferRReversed[i] * percentage; var gDeltaFrame = deltaBufferGReversed[i] * percentage; var bDeltaFrame = deltaBufferBReversed[i] * percentage; if (percentage == 1) { colorBuffer[i] = new RGB( (byte)(options.Transitions[i].Key.R), (byte)(options.Transitions[i].Key.G), (byte)(options.Transitions[i].Key.B)); } else { colorBuffer[i] = new RGB( (byte)(options.Transitions[i].Value.R + rDeltaFrame), (byte)(options.Transitions[i].Value.G + gDeltaFrame), (byte)(options.Transitions[i].Value.B + bDeltaFrame)); } } } options.OnColorsChanged(colorBuffer); } })); }