本文整理汇总了C#中Animation.Periodic方法的典型用法代码示例。如果您正苦于以下问题:C# Animation.Periodic方法的具体用法?C# Animation.Periodic怎么用?C# Animation.Periodic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Animation
的用法示例。
在下文中一共展示了Animation.Periodic方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDoubleCheckedLockingAnimation
public static Animation CreateDoubleCheckedLockingAnimation()
{
var ani = new Animation();
var address1 = 0x100;
var t = ani.Periodic(8.Seconds());
var n = 14.0;
var t_writeP1 = 1/n;
var t_writeX = 2/n;
var t_writeY = 3/n;
var t_writeS = 4/n;
var t_cacheY = 5/n;
var t_cacheX = 6/n;
var t_cacheS = 7/n;
var t_uncacheS = 8 / n;
var t_checkS = 9 / n;
var t_readX = 10/n;
var t_garbage = 11/n;
var thread1Value = t.Proper.Select(e =>
e < t_writeX ? new MemoryPoint { X = May<int>.NoValue, Y = May<int>.NoValue }
: e < t_writeY ? new MemoryPoint { X = 1, Y = May<int>.NoValue }
: new MemoryPoint { X = 1, Y = 1 });
var cacheValue = t.Proper.Select(e =>
e < t_cacheY ? new MemoryPoint { X = May<int>.NoValue, Y = May<int>.NoValue }
: e < t_cacheX ? new MemoryPoint { X = May<int>.NoValue, Y = 1 }
: new MemoryPoint { X = 1, Y = 1 });
var thread2Value = t.Proper.Select(e =>
new MemoryPoint { X = May<int>.NoValue, Y = May<int>.NoValue });
var sideMargin = 10;
var thread1X = sideMargin;
var cacheX = 107;
var thread2X = 210;
var thread2X2 = 210+50;
var rightX = thread2X2 + sideMargin*2;
//var centerX = rightX / 2;
//t.Add(new TextDesc(
// "No Acquire ⇒ Garbage",
// new Point(centerX, 5),
// new Point(0.5, 0),
// //fontWeight: FontWeights.SemiBold,
// fontSize: 18));
var mainY = 16;
var sectionLabelY = -15 + mainY;
var dividerY3 = -16 + mainY;
var dividerY1 = mainY;
var pointerY = 15 + mainY;
var valueY = 55 + mainY;
var localPointerY = 110 + mainY;
var resultY = 110 + mainY;
var dividerY2 = 140 + mainY;
var topInstructionY = 145 + mainY;
var p1 = new Point(thread1X, valueY);
var p2 = new Point(cacheX, valueY);
var p3 = new Point(thread2X, valueY);
var v1 = MakePointMemoryAnimator(address1)(thread1Value, true, p1);
var v2 = MakePointMemoryAnimator(address1)(cacheValue, true, p2);
var v3 = MakePointMemoryAnimator(address1)(thread2Value, true, p3);
var b1 = v1.Item2.WithTopLeft(p1);
var b2 = v2.Item2.WithTopLeft(p2);
var b3 = v3.Item2.WithTopLeft(p3);
var thread1LocalPointer = t.Proper.Combine(b1, (e, b) =>
e < t_writeP1 ? Tuple.Create(0, b)
: Tuple.Create(address1, b));
var thread1Pointer = t.Proper.Combine(b1, (e, b) =>
e < t_writeS ? Tuple.Create(0, b)
: Tuple.Create(address1, b));
var cachePointer = t.Proper.Combine(b2, (e, b) =>
e < t_cacheS ? Tuple.Create(0, b)
: Tuple.Create(address1, b));
var thread2Pointer = t.Proper.Combine(b3, (e, b) =>
e < t_uncacheS ? Tuple.Create(0, b)
: Tuple.Create(address1, b));
var thread2CopyX = t.Proper.Select(
e => e < t_readX ? "-" : null);
var t1LocPtrPt = new Point(thread1X, localPointerY);
var t1PtrPt = new Point(thread1X, pointerY);
var cachePtrPt = new Point(cacheX, pointerY);
var t2PtrPt = new Point(thread2X, pointerY);
var t2RetPt = new Point(thread2X, resultY);
var v4 = MakePointerAnimator("p")(thread1LocalPointer, true, t1LocPtrPt);
var v6 = MakePointerAnimator("s")(thread1Pointer, true, t1PtrPt);
var v7 = MakePointerAnimator("s")(cachePointer, true, cachePtrPt);
var v8 = MakePointerAnimator("s")(thread2Pointer, true, t2PtrPt);
var v9 = MakeBoxValueAnimator("returned")(thread2CopyX, true, t2RetPt);
var t1LocPtrR = v4.Item2.WithTopLeft(t1LocPtrPt);
var t1PtrR = v6.Item2.WithTopLeft(t1PtrPt);
var cachePtrR = v7.Item2.WithTopLeft(cachePtrPt);
var t2PtrR = v8.Item2.WithTopLeft(t2PtrPt);
//.........这里部分代码省略.........
示例2: CreateVaryQSolveSlopeAnimation
private static Animation CreateVaryQSolveSlopeAnimation(Rect rect)
{
var size = 13;
var yq = 10;
var y0 = 5;
var ani = new Animation { CreateGrid(size, rect) };
var dt = 50.Milliseconds();
var p = ani.Periodic(dt.Times(size - 1));
for (var xq = 1; xq < size; xq++) {
var slope = size.Range().Single(s => (y0 + s * xq) % size == yq);
var q = p.LimitedNewTime(dt.Times(xq - 1), dt.Times(xq));
q.Add(CreateLine(y0, slope, size, rect));
q.Add(new PointDesc(GetP(0, y0, size, rect), fill: Brushes.Red, radius: 8));
q.Add(new TextDesc(string.Format("Target = ({0}, {1}), Slope = {2}, Y-Intercept = {3}", xq, yq, slope, y0),
new Point(rect.Left + 67, rect.Bottom + 5),
new Point(0, 0), fontSize: 14));
q.Add(new PointDesc(GetP(xq, yq, size, rect), fill: Brushes.Blue, radius: 8));
}
ani.Add(new TextDesc("Varying Target, Solving Slope", new Point(rect.Left + rect.Width / 2, rect.Top - 30), new Point(0.5, 0), fontSize: 18));
return ani;
}
示例3: 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;
}
示例4: CreateVarySlopeSolveYAnimation
private static Animation CreateVarySlopeSolveYAnimation(int size, Rect rect, int xq, int yq)
{
var ani = new Animation { CreateGrid(size, rect) };
var dt = 50.Milliseconds();
var p = ani.Periodic(dt.Times(size));
for (var slope = 0; slope < size; slope++) {
var y0 = size.Range().Single(y => (y + slope * xq) % size == yq);
var q = p.LimitedNewTime(dt.Times(slope), dt.Times(slope + 1));
q.Add(CreateLine(y0, slope, size, rect));
q.Add(new PointDesc(GetP(0, y0, size, rect), fill: Brushes.Red, radius: 8));
q.Add(new TextDesc(string.Format("Target = ({0}, {1}), Slope = {2}, Y-Intercept = {3}", xq, yq, slope, y0),
new Point(rect.Left + 67, rect.Bottom + 5),
new Point(0, 0), fontSize: 14));
q.Add(new PointDesc(GetP(xq, yq, size, rect), fill: Brushes.Blue, radius: 8));
}
ani.Add(new TextDesc("Varying Slope, Solving Y-Intercept", new Point(rect.Left + rect.Width / 2, rect.Top - 30), new Point(0.5, 0), fontSize: 18));
return ani;
}
示例5: CreateAnimationOfOperations
//.........这里部分代码省略.........
var roots = keyNodes.Select(e => NestingDepthTreeNode.RootOf(e.Value.Item1)).Distinct().ToArray();
var a = new Animation();
var s = 10;
if (!double.IsNaN(focus) && !double.IsInfinity(focus)) {
var dx = focus - renderInterval.Offset;
a.Add(new LineSegmentDesc(new LineSegment(new Point(x + dx*s, 0), new Point(x + dx*s, 10000)), activeOperation.Interval.HasValue ? Brushes.Green : Brushes.Red, 1, 1.0));
}
foreach (var r in roots) a.Add(RenderTree(renderInterval, r, dealloced));
ani.LimitedNewTime(i.Seconds(), (i + dt).Seconds()).Add(a);
i += dt;
var bb = 0;
foreach (var e in keyNodes) {
Brush brush;
if (e.Key == activeOperation.Key && !double.IsInfinity(focus)) {
brush = activeOperation.Interval.HasValue ? Brushes.Green : Brushes.Red;
} else {
brush = Brushes.Yellow;
}
var inv = e.Value.Item2;
var dx = inv.Offset - renderInterval.Offset;
a.Add(new RectDesc(new Rect(x + dx * s, y - (bb+1) * s*1.1, s*inv.Length, s), fill: brush, stroke: Brushes.Black, strokeThickness: 1));
bb += 1;
}
return a;
};
foreach (var e in operations) {
activeOperation = e;
var affectedRoot =
e.Interval.HasValue ?
keyNodes.Select(n => NestingDepthTreeNode.RootOf(n.Value.Item1)).FirstOrDefault(n => NestingDepthTreeNode.GetInterval(n).Overlaps(e.Interval.Value))
: NestingDepthTreeNode.RootOf(keyNodes[e.Key].Item1);
if (e.Interval.HasValue) {
keyNodes.Add(e.Key, Tuple.Create((NestingDepthTreeNode)null, e.Interval.Value, (NestingDepthTreeNode)null));
addFrame(double.NaN);
addFrame(e.Interval.Value.Offset);
var a1 = NestingDepthTreeNode.Include(affectedRoot, e.Interval.Value.Offset, +1, +1);
a1.AdjustedNode._fakeRefCount += 2;
keyNodes[e.Key] = Tuple.Create(a1.AdjustedNode, e.Interval.Value, (NestingDepthTreeNode)null);
addFrame(e.Interval.Value.Offset);
addFrame(e.Interval.Value.Offset + e.Interval.Value.Length);
var a2 = NestingDepthTreeNode.Include(a1.NewRoot, e.Interval.Value.Offset + e.Interval.Value.Length, -1, +1);
a2.AdjustedNode._fakeRefCount += 2;
keyNodes[e.Key] = Tuple.Create(a1.AdjustedNode, e.Interval.Value, a2.AdjustedNode);
addFrame(e.Interval.Value.Offset + e.Interval.Value.Length);
addFrame(double.PositiveInfinity);
}
else {
var xs = keyNodes[e.Key];
var r = NestingDepthTreeNode.RootOf(xs.Item1);
r = NestingDepthTreeNode.Include(r, xs.Item2.Offset + xs.Item2.Length, +1, 0).NewRoot;
r = NestingDepthTreeNode.Include(r, xs.Item2.Offset, -1, 0).NewRoot;
var hh = new HashSet<int>();
foreach (var ex in NestingDepthTreeNode.FindHolesIn(NestingDepthTreeNode.GetInterval(r), r)) {
for (var ii = ex.Offset; ii < ex.Offset + ex.Length; ii++) {
hh.Add(ii);
}
}
r = NestingDepthTreeNode.Include(r, xs.Item2.Offset + xs.Item2.Length, -1, 0).NewRoot;
r = NestingDepthTreeNode.Include(r, xs.Item2.Offset, +1, 0).NewRoot;
xs.Item3._fakeRefCount -= 1;
xs.Item3._fakeRefCount -= 1;
xs.Item1._fakeRefCount -= 1;
addFrame(xs.Item2.Offset + xs.Item2.Length);
var r1 = NestingDepthTreeNode.Include(r, xs.Item2.Offset + xs.Item2.Length, +1, -1);
addFrame(xs.Item2.Offset + xs.Item2.Length);
xs.Item1._fakeRefCount -= 1;
addFrame(xs.Item2.Offset);
var r2 = NestingDepthTreeNode.Include(r1.NewRoot, xs.Item2.Offset, -1, -1);
keyNodes.Remove(e.Key);
addFrame(double.NaN);
foreach (var xxx in hh) {
dealloced.Add(xxx);
}
NestingDepthTreeNode.PartitionAroundHoles(r2.NewRoot);
addFrame(double.NaN);
}
}
var xx = new Animation();
xx.Periodic(i.Seconds()).Add(ani);
return xx;
}