public MainWindow() { this.InitializeComponent(); this.Loaded += (sender, args) => { Animate animate = new Animate((sys, extents) => { Cell<double> time = sys.Time; double t0 = time.Sample(); double ballRadius = 15; double leftWall = -extents.X + ballRadius; double rightWall = extents.X - ballRadius; double floor = -extents.Y + ballRadius; double roof = extents.Y - ballRadius; Signal gravity = new Signal(t0, 0, 0, -1200); StreamLoop<Signal> sBounceX = new StreamLoop<Signal>(); StreamLoop<Signal> sBounceY = new StreamLoop<Signal>(); Cell<Signal> velx = sBounceX.Hold(new Signal(t0, 0, 0, 350)); Cell<Signal> vely = sBounceY.Hold(gravity.Integrate(0)); Cell<Signal> posx = Signal.Integrate(velx, leftWall); Cell<Signal> posy = Signal.Integrate(vely, roof); sBounceX.Loop(BounceAt(sys, velx, posx, leftWall).OrElse(BounceAt(sys, velx, posx, rightWall))); sBounceY.Loop(BounceAt(sys, vely, posy, floor)); return Shapes.Translate(Shapes.Scale(Shapes.Circle(Colors.Red), Cell.Constant(ballRadius)), time.Lift(posx, posy, (t, x, y) => new Point(x.ValueAt(t), y.ValueAt(t)))); }, this.Placeholder.RenderSize); this.Placeholder.Children.Add(animate); animate.Start(); }; }
public Renderer(CompositionTargetSecondsTimerSystem timerSystem, Cell<DrawableDelegate> drawable, Size size, Animate animation, Cell<bool> isStarted) { this.drawable = drawable; this.size = size; Transaction.Run(() => Operational.Value(isStarted).Filter(s => s).ListenOnce(_ => timerSystem.AddAnimation(animation))); }
public MainWindow() { this.InitializeComponent(); this.Loaded += (sender, args) => { Animate animate = new Animate((sys, extents) => { Cell<double> time = sys.Time; double maxSize = 105; Cell<double> offset = time.Map(t => { double frac = t - Math.Floor(t); return (frac < 0.5 ? frac - 0.25 : 0.75 - frac) * 4.0 * maxSize; }); Cell<double> fifty = Cell.Constant(50.0); Cell<DrawableDelegate> greenBall = Shapes.Translate( Shapes.Scale(Shapes.Circle(Colors.Green), fifty), offset.Map(x => new Point(x, 0.0))); Cell<DrawableDelegate> blueBall = Shapes.Translate( Shapes.Scale(Shapes.Circle(Colors.Blue), fifty), offset.Map(y => new Point(0.0, y))); return Shapes.Over(greenBall, blueBall); }, this.Placeholder.RenderSize); this.Placeholder.Children.Add(animate); animate.Start(); }; }
public MainWindow() { this.InitializeComponent(); this.Loaded += (sender, args) => { Animate animate = new Animate((sys, extents) => { Cell<double> time = sys.Time; double maxSize = 200.0; return Shapes.Scale( Shapes.Circle(Colors.Green), time.Map(t => { double frac = t - Math.Floor(t); return (frac < 0.5 ? frac : 1.0 - frac) * maxSize; })); }, this.Placeholder.RenderSize); this.Placeholder.Children.Add(animate); animate.Start(); }; }
public void AddAnimation(Animate animation) => this.animationsToRun.Add(animation);
public Renderer(CompositionTargetSecondsTimerSystem timerSystem, Behavior <DrawableDelegate> drawable, Size size, Animate animation, Cell <bool> isStarted) { this.drawable = drawable; this.size = size; Transaction.RunVoid(() => isStarted.Values().Filter(s => s).ListenOnce(_ => timerSystem.AddAnimation(animation))); }