当前位置: 首页>>代码示例>>C#>>正文


C# TimeSpan.Times方法代码示例

本文整理汇总了C#中System.TimeSpan.Times方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.Times方法的具体用法?C# TimeSpan.Times怎么用?C# TimeSpan.Times使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.TimeSpan的用法示例。


在下文中一共展示了TimeSpan.Times方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FloorMultiple

 ///<summary>Returns the largest duration that is not larger than the given value but is a multiple of the given multiple.</summary>
 public static TimeSpan FloorMultiple(this TimeSpan value, TimeSpan multiple)
 {
     return multiple.Times(Math.Floor(value.DividedBy(multiple)));
 }
开发者ID:siddht1,项目名称:AnimatronTheTerrible,代码行数:5,代码来源:TimeUtil.cs

示例2: ShowMatrixMultiplication

 public static Animation ShowMatrixMultiplication(TimeSpan period,
                                             Rect pos,
                                             ComplexMatrix u,
                                             ComplexVector v,
                                             Ani<Brush> or,
                                             Ani<Brush> blu,
                                             Ani<Brush> bla)
 {
     var d = Math.Min(pos.Width/(u.Columns.Count + 2), pos.Height/u.Rows.Count)/2;
     pos = new Rect(pos.TopLeft, new Size(d * (u.Columns.Count + 2)*2, d*u.Rows.Count*2));
     var ur = d;
     var animation = new Animation {
         new RectDesc(new Rect(pos.X + d * 2, pos.Y, pos.Width - d * 4, pos.Height),
                      Brushes.Black,
                      strokeThickness: 0.6,
                      dashed: 5),
         new RectDesc(new Rect(pos.X, pos.Y, d * 2, pos.Height),
                      Brushes.Black,
                      strokeThickness: 0.6,
                      dashed: 5),
         new RectDesc(new Rect(pos.Right - d*2, pos.Y, d * 2, pos.Height),
                      Brushes.Black,
                      strokeThickness: 0.6,
                      dashed: 5)
     };
     var per = animation.Periodic(period);
     var s0 = per.LimitedSameTime(0.Seconds(), period.DividedBy(4));
     foreach (var r in u.Rows.Count.Range()) {
         var pp = s0.Proper;
         // input vector
         var p1 = pos.TopLeft + new Vector(d, d + r*d*2);
         var p2 = pos.TopLeft + new Vector(d*3 + r*d*2, 0);
         var p3 = pos.TopLeft + new Vector(d*3 + r*d*2, u.Rows.Count*d*2);
         s0.Add(ShowComplex(pp.Combine(blu, (p, b) => b.LerpToTransparent(p.SmoothTransition(0, 0, 1))),
                            pp.Combine(bla, (p, b) => b.LerpToTransparent(p.SmoothTransition(0, 0, 1))),
                            v.Values[r],
                            pp.Select(p => p.SmoothTransition(p1, p1, p2, p3)),
                            ur,
                            rotation: pp.Select(t => Turn.FromNaturalAngle(t.SmoothTransition(0, Math.PI/2, Math.PI/2)))));
         foreach (var c in u.Columns.Count.Range()) {
             // vector copied into matrix
             s0.Add(ShowComplex(pp.Combine(blu, (p, b) => b.LerpToTransparent(p.SmoothTransition(1, 1, 0))),
                                pp.Combine(bla, (p, b) => b.LerpToTransparent(p.SmoothTransition(1, 1, 0))),
                                v.Values[c],
                                (pos.TopLeft + new Vector(d*3 + c*d*2, d + r*d*2)),
                                ur,
                                Brushes.Transparent,
                                rotation: Turn.FromNaturalAngle(Math.PI/2)));
             // matrix
             s0.Add(ShowComplex(pp.Combine(or, (p, b) => b.LerpToTransparent(p.SmoothTransition(0, 0, 0))),
                                pp.Combine(bla, (p, b) => b.LerpToTransparent(p.SmoothTransition(0, 0, 0))),
                                u.Rows[r][c],
                                (pos.TopLeft + new Vector(d*3 + c*d*2, d + r*d*2)),
                                ur));
         }
     }
     var s1 = per.LimitedSameTime(period.Times(0.25), period.Times(0.5));
     foreach (var r in u.Rows.Count.Range()) {
         foreach (var c in u.Columns.Count.Range()) {
             s1.Add(
                 ShowComplexProduct(
                     blu,
                     or,
                     bla,
                     bla,
                     v.Values[c],
                     u.Rows[r][c],
                     (pos.TopLeft + new Vector(d*3 + c*d*2, d + r*d*2)),
                     ur,
                     s1.Proper));
         }
     }
     var s2 = per.LimitedSameTime(period.Times(0.5), period);
     foreach (var r in u.Rows.Count.Range()) {
         s2.Add(
             ShowComplexSum(
                 blu,
                 blu,
                 bla,
                 u.Rows[r].Count.Range()
                          .Select(e => u.Rows[r][e]*v.Values[e])
                          .Select(e => new ConstantAni<Complex>(e)),
                 (pos.TopLeft + new Vector(d*3, d + r*d*2)),
                 (pos.TopLeft + new Vector(d*3 + u.Columns.Count*d*2, d + r*d*2)),
                 new Vector(d*2, 0),
                 ur,
                 s2.Proper));
     }
     return animation;
 }
开发者ID:siddht1,项目名称:AnimatronTheTerrible,代码行数:90,代码来源:QuantumCircuit.cs

示例3: CeilingMultiple

 ///<summary>Returns the smallest duration that is not smaller than the given value but is a multiple of the given multiple.</summary>
 public static TimeSpan CeilingMultiple(this TimeSpan value, TimeSpan multiple)
 {
     return multiple.Times(Math.Ceiling(value.DividedBy(multiple)));
 }
开发者ID:siddht1,项目名称:AnimatronTheTerrible,代码行数:5,代码来源:TimeUtil.cs

示例4: 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


注:本文中的System.TimeSpan.Times方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。