예제 #1
0
        public MainWindow()
        {
            this.InitializeComponent();

            this.Loaded += (sender, args) =>
            {
                Animate animate = new Animate((sys, extents) =>
                {
                    Behavior <double> time   = sys.Time;
                    double maxSize           = 105;
                    Behavior <double> offset = time.Map(t =>
                    {
                        double frac = t - Math.Floor(t);
                        return((frac < 0.5 ? frac - 0.25 : 0.75 - frac) * 4.0 * maxSize);
                    });
                    Behavior <double> fifty = Behavior.Constant(50.0);
                    Behavior <DrawableDelegate> greenBall = Shapes.Translate(
                        Shapes.Scale(Shapes.Circle(Colors.Green), fifty),
                        offset.Map(x => new Point(x, 0.0)));
                    Behavior <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();
            };
        }
예제 #2
0
        public MainWindow()
        {
            this.InitializeComponent();

            this.Loaded += (sender, args) =>
            {
                Animate animate = new Animate((sys, extents) =>
                {
                    Behavior <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), Behavior.Constant(ballRadius)), time.Lift(posx.AsBehavior(), posy.AsBehavior(), (t, x, y) => new Point(x.ValueAt(t), y.ValueAt(t)))));
                }, this.Placeholder.RenderSize);
                this.Placeholder.Children.Add(animate);
                animate.Start();
            };
        }
예제 #3
0
파일: Shapes.cs 프로젝트: stjordanis/sodium
 public static Behavior <DrawableDelegate> Circle(Color color)
 {
     return(Behavior.Constant(new DrawableDelegate((d, h, o, s) =>
     {
         double radius = s;
         d.DrawEllipse(new SolidColorBrush(color), new Pen(Brushes.Black, 1), new Point(o.X, h - o.Y), radius, radius);
     })));
 }
예제 #4
0
        public Animate(AnimationDelegate animation, Size size)
        {
            TaskCompletionSource <Renderer> tcs = new TaskCompletionSource <Renderer>();

            this.renderer = tcs.Task;

            void CreateTimerSystem(object sender, EventArgs args)
            {
                CompositionTargetSecondsTimerSystem timerSystem = CompositionTargetSecondsTimerSystem.Create(((RenderingEventArgs)args).RenderingTime.TotalSeconds, e => this.Dispatcher.Invoke(() => throw e));
                Point extents = new Point(size.Width / 2, size.Height / 2);

                tcs.SetResult(new Renderer(timerSystem, Transaction.Run(() => Shapes.Translate(animation(timerSystem, extents), Behavior.Constant(extents))), size, this, this.isStarted));
                CompositionTarget.Rendering -= CreateTimerSystem;
            }

            CompositionTarget.Rendering += CreateTimerSystem;
        }