當前位置: 首頁>>代碼示例>>C#>>正文


C# Animation.Dilated方法代碼示例

本文整理匯總了C#中Animation.Dilated方法的典型用法代碼示例。如果您正苦於以下問題:C# Animation.Dilated方法的具體用法?C# Animation.Dilated怎麽用?C# Animation.Dilated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Animation的用法示例。


在下文中一共展示了Animation.Dilated方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateComplexTransformationAnimation

        public static Animation CreateComplexTransformationAnimation()
        {
            var matrixFill = (Brush)Brushes.Orange.LerpToTransparent(0.5);
            var vectorFill = (Brush)Brushes.Blue.LerpToTransparent(0.7);

            var s = new Complex(Math.Sqrt(0.5), 0);
            var si = new Complex(0, s.Real);
            var c1 = Complex.FromPolarCoordinates(Math.Sqrt(0.75), 0);
            var c2 = Complex.FromPolarCoordinates(Math.Sqrt(0.2), Math.PI / 4);
            var m = ComplexMatrix.FromSquareData(s, si, -s, si);
            var v = new ComplexVector(new[] { c1, c2 });
            var u = 50;

            var animation = new Animation {
                new TextDesc("Matrix Multiplication with Complex Numbers",
                             new Point(25 + u*(v.Values.Count + 2), 5),
                             new Point(0.5, 0),
                             fontSize: 15,
                             foreground: Brushes.Gray),
            };
            var r = new Rect(25, 25, u*2*(v.Values.Count + 2), u*2*v.Values.Count);
            var p = animation.Dilated(0.5.Seconds()).Periodic(10.Seconds());
            var qx1 = p.Proper.Select(e => (e * 10 - 9).Clamp(0, 1));
            var qx2 = p.Proper.Select(e => ((e - 0.6) * 10).Clamp(0, 1));

            p.Add(ShowMatrixMultiplication(
                10.Seconds(),
                r,
                m,
                v,
                qx1.Select(matrixFill.LerpToTransparent),
                qx1.Select(vectorFill.LerpToTransparent),
                qx1.Select(x => (Brush)Brushes.Black.LerpToTransparent(x))));

            p.LimitedSameTime(0.Seconds(), 10.Seconds()).Add(ShowMatrixMultiplication(
                100000000.Seconds(),
                r,
                m,
                v,
                qx2.Select(x => matrixFill.LerpToTransparent(1 - x)),
                qx2.Select(x => vectorFill.LerpToTransparent(1 - x)),
                qx2.Select(x => (Brush)Brushes.Black.LerpToTransparent(1 - x))));

            return animation;
        }
開發者ID:siddht1,項目名稱:AnimatronTheTerrible,代碼行數:45,代碼來源:QuantumCircuit.cs

示例2: CreateCircuitAnimation

        public static Animation CreateCircuitAnimation(double span,
                                                       TimeSpan duration, 
                                                       IReadOnlyList<CircuitOperationWithStyle> ops, 
                                                       IReadOnlyList<CircuitInputWithStyle> ins, 
                                                       string desc, 
                                                       IReadOnlyList<string[][]> wireLabels = null, 
                                                       string[] stateLabels = null, 
                                                       bool showMatrix = true, 
                                                       double wireSpace = 80)
        {
            var matrixFill = (Brush)Brushes.Orange.LerpToTransparent(0.5);

            var vals = ins.Select(e => ops.Stream(e.Value, (a, x) => x.Operation*a, streamSeed: true).ToArray()).ToArray();

            var numOp = ops.Count;
            var numIn = ins.Count;
            var maxIn = numOp + 1;
            var numState = ins.First().Value.Values.Count;
            var numWire = (int)Math.Round(Math.Log(numState, 2));
            var matrixWidth = 150.0;
            var cellRadius = matrixWidth / (vals[0][0].Values.Count + 2) / 2;
            var matrixRadius = matrixWidth / 2;
            var opXs = numOp.Range().Select(i => -cellRadius+span*(i+0.75)/maxIn).ToArray();

            var sweepX = Ani.Anon(t => new Point(t.DividedBy(duration).LerpTransition(-cellRadius * 2, span - cellRadius * 2), 0).Sweep(new Vector(0, 1000)));
            var opTs = opXs.Select(x => new {s = duration.Times((x - matrixRadius + cellRadius*2)/span), f = duration.Times((x + matrixRadius)/span)}).ToArray();

            var wireYs = numWire.Range().Select(i => numWire == 1 ? 20 + wireSpace/2 : (wireSpace / 2 + i * wireSpace / 2 / (numWire - 1))).ToArray();
            var animation = new Animation {
                // top description
                new TextDesc(desc,
                             new Point(span/2.0 - (numOp == 1 ? cellRadius : 0), 5),
                             new Point(0.5, 0),
                             fontSize: 15,
                             foreground: Brushes.Gray),
                // wires
                wireYs.Select(y => new LineSegmentDesc(new Point(0, y).Sweep(new Vector(span+300, 0))))
            };
            if (showMatrix) {
                // static matrices
                animation.Add(
                    numOp.Range()
                         .Select(i => ShowMatrix(
                             new Rect(opXs[i] - matrixRadius, wireSpace+20, matrixRadius*2, matrixRadius*2),
                             ops[i].Operation,
                             matrixFill,
                             Brushes.Black)));
            }

            var offsetTimelines =
                ins.Count.Range()
                     .Select(
                         i => animation
                                  .Dilated(
                                      1.Seconds(),
                                      -duration.DividedBy(ins.Count).Times(i))
                                  .Periodic(duration))
                     .ToArray();

            // sweep line
            foreach (var p in offsetTimelines) {
                p.Add(new LineSegmentDesc(sweepX, Brushes.Red, 0.5, 4));
            }

            // state labels
            var tts = opTs.Select(e => e.s.LerpTo(e.f, 0.4));
            var wd = numIn.Range().Select(inid => numWire.Range().Select(wid => (numOp + 1).Range().Select(tid => {
                var label = wireLabels == null ? new[] {"On", "Off"} : wireLabels[wid][tid];
                var p = numState.Range().Where(i => ((i >> wid) & 1) == 0).Select(i => vals[inid][tid].Values[i].SquaredMagnitude()).Sum();
                if (p < 0.001) return label[1];
                if (p < 0.01) return string.Format("~{0}", label[1]);
                if (p < 0.49) return string.Format("~{0}:{1:0}%", label[1], (1 - p) * 100);

                if (p > 0.999) return label[0];
                if (p > 0.99) return string.Format("~{0}", label[0]);
                if (p > 0.51) return string.Format("~{0}:{1:0}%", label[0], p * 100);

                return string.Format("{0}/{1}", label[0], label[1]);
            }).ToArray()).ToArray()).ToArray();
            foreach (var i in numIn.Range()) {
                foreach (var j in numWire.Range()) {
                    animation.Add(
                        new TextDesc(
                            Ani.Anon(t => (t + duration.DividedBy(numIn).Times(i)).Mod(duration))
                               .Select(t => wd[i][j][tts.TakeWhile(c => t >= c).Count()]),
                            Ani.Anon(
                                t =>
                                new Point((t.DividedBy(duration) + i * 1.0 / numIn).ProperMod(1).LerpTransition(-cellRadius * 2, span - cellRadius * 2), wireYs[j]))));
                }
            }

            // matrix multiplications
            if (showMatrix) {
                foreach (var i in numIn.Range()) {
                    foreach (var j in numOp.Range()) {
                        var p = offsetTimelines[i].LimitedNewTime(opTs[j].s, opTs[j].f);
                        var r = new Rect(opXs[j] - matrixRadius, wireSpace + 20, matrixRadius * 2, matrixRadius * 2);
                        p.Add(
                            ShowMatrixMultiplication(
                                opTs[j].f - opTs[j].s,
//.........這裏部分代碼省略.........
開發者ID:siddht1,項目名稱:AnimatronTheTerrible,代碼行數:101,代碼來源:QuantumCircuit.cs

示例3: CreateComplexSumAnimation

        public static Animation CreateComplexSumAnimation()
        {
            var matrixFill = (Brush)Brushes.Orange.LerpToTransparent(0.5);
            var vectorFill = (Brush)Brushes.Blue.LerpToTransparent(0.7);
            var c1 = new Complex(-0.5, -0.5) * Math.Sqrt(0.5);
            var c2 = new Complex(-0.5, 0.5);
            var r = 50;
            var cy = 100;
            var x1 = 125/2;
            var x2 = 350/2;
            var x3 = x2 + (x2-x1);
            var f = 14;

            var animation = new Animation {
                new TextDesc("+", new Point((x1 + x2)/2.0, cy), new Point(0.5, 0.5), fontSize: 20),
                new TextDesc("=", new Point((x3 + x2)/2.0, cy), new Point(0.5, 0.5), fontSize: 20),
                new TextDesc(c1.ToPrettyString(), new Point(x1, cy - r), new Point(0.5, 1), fontSize: f),
                new TextDesc(c2.ToPrettyString(), new Point(x2, cy - r), new Point(0.5, 1), fontSize: f),
                new TextDesc((c1 + c2).ToPrettyString(), new Point(x3, cy - r), new Point(0.5, 1), fontSize: f),

                new TextDesc(c1.ToMagPhaseString(), new Point(x1, cy + r), new Point(0.5, 0), fontSize: f),
                new TextDesc(c2.ToMagPhaseString(), new Point(x2, cy + r), new Point(0.5, 0), fontSize: f),
                new TextDesc((c1 + c2).ToMagPhaseString(), new Point(x3, cy + r), new Point(0.5, 0), fontSize: f),
                new TextDesc("Adding Complex Numbers: Place Arrows End to End",
                             new Point(x2, 5),
                             new Point(0.5, 0),
                             fontSize: 15,
                             foreground: Brushes.Gray),

                ShowComplex(vectorFill,
                            Brushes.Black,
                            c1,
                            new Point(x1, cy),
                            r),
                ShowComplex(matrixFill,
                            Brushes.Black,
                            c2,
                            new Point(x2, cy),
                            r)
            };
            var p = animation.Dilated(0.4.Seconds()).Periodic(10.Seconds());
            p.LimitedSameTime(0.Seconds(), 9.5.Seconds()).Add(ShowComplexSum(
                Brushes.Transparent,
                vectorFill.LerpTo(matrixFill, 0.5),
                Brushes.Black,
                new Ani<Complex>[] {c1, c2},
                new Point(x1, cy),
                new Point(x3, cy),
                new Vector(x2-x1, 0),
                r,
                p.Proper));

            var s2 = p.LimitedSameTime(9.5.Seconds(), 10.Seconds());
            s2.Add(ShowComplex(Ani.Anon(t => vectorFill.LerpTo(matrixFill, 0.5).LerpToTransparent(s2.Proper.ValueAt(t))),
                               Ani.Anon(t => (Brush)Brushes.Black.LerpToTransparent(s2.Proper.ValueAt(t))),
                               c1 + c2,
                               new Point(x3, cy),
                               r));

            return animation;
        }
開發者ID:siddht1,項目名稱:AnimatronTheTerrible,代碼行數:61,代碼來源:QuantumCircuit.cs

示例4: CreateComplexProductAnimation

        public static Animation CreateComplexProductAnimation()
        {
            var matrixFill = (Brush)Brushes.Orange.LerpToTransparent(0.5);
            var vectorFill = (Brush)Brushes.Blue.LerpToTransparent(0.7);
            var c1 = new Complex(1, 1) / 2;
            var c2 = new Complex(-1, 1) / 2;
            var r = 50;
            var cy = 100;
            var x1 = 125 / 2;
            var x2 = 350 / 2;
            var x3 = x2 + (x2 - x1);
            var f = 14;

            var animation = new Animation {
                new TextDesc("*", new Point((x1 + x2)/2.0, cy), new Point(0.5, 0.5), fontSize: 20),
                new TextDesc("=", new Point((x3 + x2)/2.0, cy), new Point(0.5, 0.5), fontSize: 20),
                new TextDesc(c1.ToPrettyString(), new Point(x1, cy - r), new Point(0.5, 1), fontSize: f),
                new TextDesc(c2.ToPrettyString(), new Point(x2, cy - r), new Point(0.5, 1), fontSize: f),
                new TextDesc((c1*c2).ToPrettyString(), new Point(x3, cy - r), new Point(0.5, 1), fontSize: f),

                new TextDesc(c1.ToMagPhaseString(), new Point(x1, cy + r), new Point(0.5, 0), fontSize: f),
                new TextDesc(c2.ToMagPhaseString(), new Point(x2, cy + r), new Point(0.5, 0), fontSize: f),
                new TextDesc((c1*c2).ToMagPhaseString(), new Point(x3, cy + r), new Point(0.5, 0), fontSize: f),
                new TextDesc("Complex Product: Multiply Magnitudes, Add Phases",
                             new Point(x2, 5),
                             new Point(0.5, 0),
                             fontSize: 15,
                             foreground: Brushes.Gray),

                ShowComplex(vectorFill,
                            Brushes.Black,
                            c1,
                            new Point(x1, cy),
                            r),
                ShowComplex(matrixFill,
                            Brushes.Black,
                            c2,
                            new Point(x2, cy),
                            r)
            };

            var p = animation.Dilated(0.4.Seconds()).Periodic(10.Seconds());
            var s1 = p.LimitedSameTime(0.Seconds(), 3.Seconds());
            s1.Add(ShowComplex(vectorFill,
                               Brushes.Black,
                               c1,
                               Ani.Anon(
                                   t =>
                                   new Point(x1, cy).SmoothLerpTo(new Point(x3, cy), (s1.Proper.ValueAt(t)*1.5).Min(1))
                                   + new Vector(0, (s1.Proper.ValueAt(t)*1.5).Min(1).LerpTransition(0, -25, 0))),
                               r,
                               rotation: Ani.Anon(t => Turn.FromNaturalAngle(0.0.SmoothLerpTo(Math.PI/2, (s1.Proper.ValueAt(t)*2).Min(1))))));
            s1.Add(ShowComplex(matrixFill,
                               Brushes.Black,
                               c2,
                               Ani.Anon(
                                   t =>
                                   new Point(x2, cy).SmoothLerpTo(new Point(x3, cy), (s1.Proper.ValueAt(t)*1.5).Min(1))
                                   + new Vector(0, (s1.Proper.ValueAt(t)*1.5).Min(1).LerpTransition(0, -25, 0))),
                               r));
            var sb = p.LimitedSameTime(3.Seconds(), 9.Seconds());
            sb.Add(
                ShowComplexProduct(vectorFill,
                                   matrixFill,
                                   Brushes.Black,
                                   Brushes.Black,
                                   c1,
                                   c2,
                                   new Point(x3, cy),
                                   r,
                                   Ani.Anon(t => (sb.Proper.ValueAt(t)*1.2).Min(1)),
                                   vectorFill.LerpTo(matrixFill, 0.5)));

            var s2 = p.LimitedSameTime(9.Seconds(), 9.5.Seconds());
            s2.Add(ShowComplex(Ani.Anon(t => vectorFill.LerpTo(matrixFill, 0.5).LerpToTransparent(s2.Proper.ValueAt(t))),
                               Ani.Anon(t => (Brush)Brushes.Black.LerpToTransparent(s2.Proper.ValueAt(t))),
                               c1*c2,
                               new Point(x3, cy),
                               r));

            return animation;
        }
開發者ID:siddht1,項目名稱:AnimatronTheTerrible,代碼行數:82,代碼來源:QuantumCircuit.cs


注:本文中的Animation.Dilated方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。