本文整理汇总了C#中Animation.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Animation.Add方法的具体用法?C# Animation.Add怎么用?C# Animation.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Animation
的用法示例。
在下文中一共展示了Animation.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateGrid
private static Animation CreateGrid(int size, Rect rect)
{
var ani = new Animation();
for (var i = 0; i < size; i++) {
ani.Add(new LineSegmentDesc(new Point(GetX(i, size, rect), rect.Top).Sweep(new Vector(0, rect.Height)), Brushes.Gray, 1));
ani.Add(new LineSegmentDesc(new Point(rect.Left, GetY(i, size, rect)).Sweep(new Vector(rect.Width, 0)), Brushes.Gray, 1));
}
return ani;
}
示例2: OnStartAnimationButtonClicked
void OnStartAnimationButtonClicked(object sender, EventArgs e)
{
SetIsEnabledButtonState(false, true);
var parentAnimation = new Animation();
var scaleUpAnimation = new Animation(v => image.Scale = v, 1, 2, Easing.SpringIn);
var rotateAnimation = new Animation(v => image.Rotation = v, 0, 360);
var scaleDownAnimation = new Animation(v => image.Scale = v, 2, 1, Easing.SpringOut);
parentAnimation.Add(0, 0.5, scaleUpAnimation);
parentAnimation.Add(0, 1, rotateAnimation);
parentAnimation.Add(0.5, 1, scaleDownAnimation);
parentAnimation.Commit(this, "ChildAnimations", 16, 4000, null, (v, c) => SetIsEnabledButtonState(true, false));
// new Animation {
// { 0, 0.5, new Animation (v => image.Scale = v, 1, 2) },
// { 0, 1, new Animation (v => image.Rotation = v, 0, 360) },
// { 0.5, 1, new Animation (v => image.Scale = v, 2, 1) }
// }.Commit (this, "ChildAnimations", 16, 4000, null, (v, c) => SetIsEnabledButtonState (true, false));
}
示例3: CreateLine
private static Animation CreateLine(int y0, int slope, int size, Rect rect)
{
if (slope > size / 2) slope -= size;
var ani = new Animation();
var s = new Vector(rect.Width, -slope*rect.Height);
var c = new Point(GetX(0, size, rect), GetY(y0, size, rect));
var L = (c - s).To(c + s);
var w = slope == 0 ? 0 : rect.Width / Math.Abs(slope);
for (var i = -3; i <= Math.Abs(slope)+2; i++) {
var Li = ClipLine(L + new Vector(w, 0)*i, rect);
if (Li.HasValue) {
ani.Add(new LineSegmentDesc(Li.Value, Brushes.Black, 2));
}
if (slope == 0) break;
}
return ani;
}
示例4: SetTranslationAsync
/// <summary>
/// Sets the translation.
/// </summary>
/// <param name="translation">Translation.</param>
private Task SetTranslationAsync(double translation, bool animate, double delta,
DateTime startTime, DateTime endTime)
{
if (Children.Count == 0)
return Task.FromResult (true);
var tcs = new TaskCompletionSource<bool> ();
double speed = 250.0;
// velocity:
if(startTime != DateTime.MinValue)
{
var deltaT = (endTime - startTime).Milliseconds;
double velocity_X = (double)deltaT / (double)delta;
speed = Math.Abs((translation -_childLayout.TranslationX) * velocity_X);
}
var animation = new Animation ();
if (animate)
animation.Add(0.0, 1.0, new Animation((d) => _childLayout.TranslationX = d,
_childLayout.TranslationX, translation));
else
_childLayout.TranslationX = translation;
if (animate)
{
var endAnimation = new Animation ((d) => {
}, 0, 1, Easing.CubicInOut, () => {
tcs.SetResult (true);
});
animation.Add (0.0, 1.0, endAnimation);
animation.Commit (this, "Translate", 16, Math.Min (350, (uint)speed), Easing.CubicOut);
}
else
{
tcs.SetResult (true);
}
return tcs.Task;
}
示例5: OnButton3Clicked
void OnButton3Clicked(object sender, EventArgs args)
{
Button button = (Button)sender;
// Create parent animation object.
Animation parentAnimation = new Animation();
// Create "up" animation and add to parent.
Animation upAnimation = new Animation(
v => button.Scale = v,
1, 5, Easing.SpringIn,
() => Debug.WriteLine("up finished"));
parentAnimation.Add(0, 0.5, upAnimation);
// Create "down" animation and add to parent.
Animation downAnimation = new Animation(
v => button.Scale = v,
5, 1, Easing.SpringOut,
() => Debug.WriteLine("down finished"));
parentAnimation.Insert(0.5, 1, downAnimation);
// Commit parent animation
parentAnimation.Commit(
this, "Animation3", 16, 5000, null,
(v, c) => Debug.WriteLine("parent finished: {0} {1}", v, c));
}
示例6: 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;
}
示例7: Activate
/// <summary>
/// Initializes a new instance of the <see cref="NControl.Controls.TabStripControl"/> class.
/// </summary>
/// <param name="view">View.</param>
public void Activate (TabItem tabChild, bool animate)
{
var existingChild = Children.FirstOrDefault (t => t.View ==
_contentView.Children.FirstOrDefault (v => v.IsVisible));
if (existingChild == tabChild)
return;
var idxOfExisting = existingChild != null ? Children.IndexOf (existingChild) : -1;
var idxOfNew = Children.IndexOf (tabChild);
if (idxOfExisting > -1 && animate)
{
_inTransition = true;
// Animate
var translation = idxOfExisting < idxOfNew ?
_contentView.Width : - _contentView.Width;
tabChild.View.TranslationX = translation;
if (tabChild.View.Parent != _contentView)
_contentView.Children.Add(tabChild.View);
else
tabChild.View.IsVisible = true;
var newElementWidth = _buttonStack.Children.ElementAt (idxOfNew).Width;
var newElementLeft = _buttonStack.Children.ElementAt (idxOfNew).X;
var animation = new Animation ();
var existingViewOutAnimation = new Animation ((d) => existingChild.View.TranslationX = d,
0, -translation, Easing.CubicInOut, () => {
existingChild.View.IsVisible = false;
_inTransition = false;
});
var newViewInAnimation = new Animation ((d) => tabChild.View.TranslationX = d,
translation, 0, Easing.CubicInOut);
var existingTranslation = _indicator.TranslationX;
var indicatorTranslation = newElementLeft;
var indicatorViewAnimation = new Animation ((d) => _indicator.TranslationX = d,
existingTranslation, indicatorTranslation, Easing.CubicInOut);
var startWidth = _indicator.Width;
var indicatorSizeAnimation = new Animation ((d) => _indicator.WidthRequest = d,
startWidth, newElementWidth, Easing.CubicInOut);
animation.Add (0.0, 1.0, existingViewOutAnimation);
animation.Add (0.0, 1.0, newViewInAnimation);
animation.Add (0.0, 1.0, indicatorViewAnimation);
animation.Add (0.0, 1.0, indicatorSizeAnimation);
animation.Commit (this, "TabAnimation");
}
else
{
// Just set first view
_contentView.Children.Clear();
_contentView.Children.Add(tabChild.View);
}
foreach (var tabBtn in _buttonStack.Children)
((TabBarButton)tabBtn).IsSelected = _buttonStack.Children.IndexOf(tabBtn) == idxOfNew;
if (TabActivated != null)
TabActivated(this, idxOfNew);
}
示例8: 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;
}
示例9: CreateAnimationOfOperations
private static Animation CreateAnimationOfOperations(Interval renderInterval, Interval targetInterval, params Operation[] operations)
{
var keyNodes = new Dictionary<int, Tuple<NestingDepthTreeNode, Interval, NestingDepthTreeNode>>();
var activeOperation = default(Operation);
var dt = 1.0;
var ani = new Animation();
ani.Add(new TextDesc("Using a Tree to Track Referenced Intervals", new Point(250, 5), new Point(0, 0), fontSize:20));
ani.Add(new TextDesc("Referenced" + Environment.NewLine + "Intervals", new Point(10, 80)));
ani.Add(new TextDesc("Tree", new Point(10, 220)));
ani.Add(new TextDesc("Nesting" + Environment.NewLine + "Depth", new Point(10, 350)));
ani.Add(new LineSegmentDesc(new Point(0, 30).Sweep(new Vector(10000, 0)), Brushes.Black, 1));
ani.Add(new LineSegmentDesc(new Point(0, 100).Sweep(new Vector(10000, 0)), Brushes.Black, 1));
ani.Add(new LineSegmentDesc(new Point(0, 300).Sweep(new Vector(10000, 0)), Brushes.Black, 1));
ani.Add(new LineSegmentDesc(new Point(75, 0).Sweep(new Vector(0, 10000)), Brushes.Black, 1));
var i = 0.0;
var dealloced = new HashSet<int>();
for (var i2 = 0; i2 < renderInterval.Length; i2++) {
if (i2 + renderInterval.Offset < targetInterval.Offset || i2 + renderInterval.Offset >= targetInterval.Offset + targetInterval.Length) {
dealloced.Add(i2 + renderInterval.Offset);
}
}
var x = 100;
var y = 90;
Func<double, Animation> addFrame = focus => {
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;
//.........这里部分代码省略.........
示例10: 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,
//.........这里部分代码省略.........
示例11: RenderTree
private static Animation RenderTree(Interval renderInterval, NestingDepthTreeNode root, HashSet<int> dealloced)
{
var v = renderInterval;
var ani = new Animation();
var r = 10;
var query = new Dictionary<int, int>();
var x = 100;
var y = 350;
for (var i = 0; i < v.Length; i++) {
var h = NestingDepthTreeNode.QueryNestingDepthAt(root, i+v.Offset);
query[i+v.Offset] = h;
if (h== -1) throw new Exception();
ani.Add(new RectDesc(new Rect(x + i * r, y - h * r - 1, r, h * r + 1), fill: Brushes.Black, stroke: Brushes.Black, strokeThickness: 0));
if (dealloced.Contains(i+v.Offset)) {
ani.Add(new RectDesc(new Rect(x + i * r, y - 0.5 * r - 1, r, 1 * r + 1), fill: Brushes.Red, stroke: Brushes.Orange, strokeThickness: 1));
}
}
var y2 = 125;
Action<NestingDepthTreeNode, int> paintNode = null;
paintNode = (n, l) => {
if (n == null) return;
var p = new Point(x + (n._offset-v.Offset)*r, y2 + l*r*5);
if (n._parent != null) {
var q = new Point(x + (n._parent._offset - v.Offset) * r, y2 + (l - 1) * r * 5);
var b1 = false;
var b2 = false;
for (var i = Math.Min(n._offset, n._parent._offset); i < Math.Max(n._offset, n._parent._offset); i++) {
b1 |= query[i] != 0;
b2 |= query[i] == 0;
}
ani.Add(new LineSegmentDesc(new LineSegment(p, q), b1 && b2 ? Brushes.Red : b2 ? Brushes.Red : Brushes.Black, 1));
}
if (n._less != null) paintNode(n._less, l + 1);
if (n._more != null) paintNode(n._more, l + 1);
ani.Add(new RectDesc(new Rect(new Point(p.X - 18, p.Y - 22), new Size(36, 44)), n._fakeRefCount > 1 ? Brushes.Black : Brushes.Red, n._fakeRefCount > 0 ? Brushes.Gray : Brushes.Red, 1));
var s = "d=" + n._adjust +Environment.NewLine + "t=" + n._subTreeTotalAdjust + Environment.NewLine + "m=" + n._subTreeRelativeMinimum;
ani.Add(new TextDesc(s, new Point(p.X - 16, p.Y - 20), new Point(0, 0)));
//var s = (n._adjust > 0 ? "+" : "") + n._adjust;
//ani.Add(new PointDesc(p, n._fakeRefCount > 1 ? Brushes.Black : Brushes.Red, n._fakeRefCount > 0 ? Brushes.Gray : Brushes.Red, 15, 1));
//ani.Add(new TextDesc(s, new Point(p.X - 8, p.Y - 8), new Point(0, 0)));
};
paintNode(root, 0);
return ani;
}
示例12: MakeSuperpositionAnimation
private static Animation MakeSuperpositionAnimation(Ani<Point> aniCenter, IReadOnlyDictionary<string, Ani<Complex>> vector, Brush[] colors)
{
var tau = 2*Math.PI;
var aniVector =
(from keyVal in vector
select from component in keyVal.Value
select new {
label = keyVal.Key,
value = new Complex(component.Real, -component.Imaginary),
scale = component.Magnitude < 0.1 ? component.Magnitude * 10 : 1
}).ToArray()
.AniAll();
var aniStartingPhase = from component in aniVector
select (from e in component
where e.value.Magnitude > 0
select -e.scale * e.value / e.value.Magnitude
).Sum()
.Phase;
var aniBars =
from component in aniVector
from startingPhase in aniStartingPhase
select component.Select((e, i) => new {
Label = e.label,
Width = 20*e.scale,
Height = e.value.Magnitude * (e.scale < 0.001 ? 0 : (100 / e.scale)),
Angle = e.value.Phase.ProperMod(tau),
Color = colors[i%colors.Length]
}).OrderBy(e => (e.Angle - startingPhase).ProperMod(tau)).ToArray();
var ani = new Animation();
var c = 0;
Func<double, Vector> angleToVector = theta => new Vector(Math.Cos(theta), Math.Sin(theta));
var aniBorderDisplacements = from bars in aniBars
select bars.Stream(
default(Vector),
(acc, bar) => acc + angleToVector(bar.Angle + tau/4)*bar.Width,
streamSeed: true).ToArray();
var aniAvgDisplacement = from borderDisplacements in aniBorderDisplacements
select borderDisplacements.Average();
var aniBorderPoints = from center in aniCenter
from avgDisplacement in aniAvgDisplacement
from borderDisplacements in aniBorderDisplacements
select (from borderDisplacement in borderDisplacements
select center + borderDisplacement - avgDisplacement).ToArray();
foreach (var i in vector.Count.Range()) {
var aniPt = from borderPoints in aniBorderPoints
select borderPoints[i];
var aniBar = from bars in aniBars
select bars[i];
var dw = from bar in aniBar
select angleToVector(bar.Angle + tau/4)*bar.Width;
var dh = from bar in aniBar
select angleToVector(bar.Angle)*bar.Height;
ani.Add(new PolygonDesc(pos: from pt in aniPt
from w in dw
from h in dh
select new[] {
pt + w*c,
pt + w*(1 - c),
pt + w*(1 - c) + h,
pt + w*c + h
}.AsEnumerable(),
fill: from bar in aniBar
select bar.Color));
ani.Add(new TextDesc(text: from bar in aniBar
select bar.Label,
pos: from h in dh
from w in dw
from pt in aniPt
select pt + h + w/2 + h.Normal()*5 - w.Normal()*2,
reference: new Point(0, 0.5),
fontSize: from bar in aniBar
select bar.Width*1.2,
direction: from bar in aniBar
select Dir.FromNaturalAngle(bar.Angle)));
}
ani.Add(new PolygonDesc(aniBorderPoints.Select(e => e.AsEnumerable()), Brushes.Gray, 1, 2));
return ani;
}
示例13: MakeScalingAnimation
private static Animation MakeScalingAnimation(Point center, IEnumerable<Complex> input, Ani<Complex> scale, Point? scalingTextPos = null)
{
var n = input.Count();
var I = ComplexMatrix.MakeIdentity(n);
var ani = new Animation {
MakeTransformAnimation(center,
input,
from s in scale
select I*s)
};
if (scalingTextPos.HasValue) {
ani.Add(new TextDesc(text: from s in scale
select string.Format("Current Scale Factor = = {0}",
s.Imaginary == 0
? s.Real.ToString("0.0")
: s.ToPrettyString("0.0")),
pos: scalingTextPos));
ani.Add(new RectDesc(
new Rect(scalingTextPos.Value + new Vector(130, -5) + new Vector(-10, -5), new Size(20, 10)),
stroke: from s in scale select s.Imaginary != 0 ? (Brush)Brushes.Transparent : Brushes.Black,
strokeThickness: 1,
dashed: 3));
ani.Add(new RectDesc(
from s in scale select new Rect(scalingTextPos.Value + new Vector(130, -5) + new Vector(s.Real.Min(0)*10, -5), new Size(s.Real.Abs()*10, 10)),
fill: from s in scale select s.Imaginary != 0 ? (Brush)Brushes.Transparent : Brushes.Green));
ani.Add(QuantumCircuit.ShowComplex(
Brushes.Transparent,
from s in scale select s.Imaginary == 0 ? (Brush)Brushes.Transparent : Brushes.Black,
scale,
scalingTextPos.Value + new Vector(130, -5),
10,
sweepFill: from s in scale select s.Imaginary == 0 ? (Brush)Brushes.Transparent : Brushes.Green,
valueGuideStroke: from s in scale select s.Imaginary == 0 ? (Brush)Brushes.Transparent : Brushes.Black));
}
return ani;
}
示例14: MakeRotationAnimation
private static Animation MakeRotationAnimation(Point center, IEnumerable<Complex> input, TimeSpan dt, Point? rotationTextPos = null)
{
var aniTheta = Ani.Anon(t => (t.DividedBy(dt)*Math.PI*2).ProperMod(Math.PI*2));
var aniMatrix = from theta in aniTheta
select ComplexMatrix.FromSquareData(Math.Cos(theta), Math.Sin(theta), -Math.Sin(theta), Math.Cos(theta));
var ani = new Animation {
MakeTransformAnimation(center, input, aniMatrix),
};
if (rotationTextPos.HasValue) {
ani.Add(new TextDesc(text: from theta in aniTheta
select string.Format("Current Rotation = {0:000}° = ", theta*180/Math.PI),
pos: rotationTextPos.Value,
reference: new Point(0.5, 1)));
ani.Add(QuantumCircuit.ShowComplex(
Brushes.Transparent,
Brushes.Black,
from theta in aniTheta select Complex.FromPolarCoordinates(1, theta),
rotationTextPos.Value + new Vector(70, -5),
10,
sweepFill: Brushes.Yellow,
valueGuideStroke: Brushes.Transparent,
sweepScale: 1.0));
}
return ani;
}
示例15: CreateCellAnimation
public static Animation CreateCellAnimation()
{
var animation = new Animation();
var liqs = new List<Liqs>();
var rng = new Random();
var n = 300;
var w = 400.0;
foreach (var i in n.Range()) {
var p = new Point(rng.NextDouble()*w, rng.NextDouble()*w);
var a = i*2*Math.PI/n;
var v = new Vector(Math.Sin(a), Math.Cos(a));
//p = new Point(w/2,w/2) + (w/8+rng.NextDouble()*5)* v;
var l1 = new Liqs {
P = p,
V = new Vector(rng.NextDouble() - 0.5, rng.NextDouble() - 0.5) * 25,
Charge = -1 //(rng.Next(2) * 2 - 1)
};
var l2 = new Liqs {
P = p + v*20*(rng.Next(3)==0?-1:1) + 8*new Vector(rng.NextDouble() * -0.5, rng.NextDouble() * -0.5),
V = new Vector(rng.NextDouble()-0.5, rng.NextDouble()-0.5)*10,
Partner = l1,
Charge = -l1.Charge
};
l1.Partner = l2;
liqs.Add(l1);
liqs.Add(l2);
//animation.Add(new LineSegmentDesc(Ani.Anon(t => l1.P.To(l2.P)), Brushes.Black, 1.0, 3));
animation.Add(new PointDesc(Ani.Anon(t => l1.P), Brushes.Transparent, l1.Charge == -1 ? Brushes.Red : Brushes.Blue, 3, 0.0));
animation.Add(new PointDesc(Ani.Anon(t => l2.P), Brushes.Transparent, l2.Charge == -1 ? Brushes.Red : Brushes.Blue, 3, 0.0));
}
foreach (var i in (n*4).Range()) {
var p = new Point((rng.NextDouble() * 2 - 1) *w / 2 + w / 2, (rng.NextDouble() * 2 - 1) * w / 2 + w / 2);
var a = i * 2 * Math.PI / n;
var v = new Vector(Math.Sin(a), Math.Cos(a));
//p = new Point(w / 2, w / 2) + ((rng.Next(12) == 0 ? w / 32 : w * 0.25 * (rng.NextDouble() * 0.2 + 0.9)) + rng.NextDouble() * 5) * v;
var l1 = new Liqs {
P = p,
Charge = 0
};
liqs.Add(l1);
animation.Add(new PointDesc(Ani.Anon(t => l1.P), Brushes.Transparent, Brushes.DarkGreen, 2, 0.0));
}
Action<TimeSpan> sstep = dt => {
var ds = dt.TotalSeconds;
foreach (var p in liqs) {
var a = new Vector(0, 0);
foreach (var q in liqs) {
if (q == p) continue;
a += p.ForceTowards(q) * 1;
}
var f = 5;
if (p.P.X > w-10) a -= f*new Vector(1, 0);
if (p.P.X < 10) a -= f * new Vector(-1, 0);
if (p.P.Y > w - 10) a -= f * new Vector(0, 1);
if (p.P.Y < 10) a -= f * new Vector(0, -1);
var t = 1.0;
//foreach (var q in liqs) {
// if (q == p || q == p.Partner) continue;
// var r = GeometryUtilities.LineDefinedByMovingEndPointsCrossesOrigin(q.P.To(q.P - p.V * ds * t), q.Partner.P.To(q.Partner.P - p.V * ds * t), p.P);
// if (r.HasValue) t *= r.Value.T;
//}
//foreach (var q in liqs) {
// if (q == p || q == p.Partner) continue;
// var r = GeometryUtilities.LineDefinedByMovingEndPointsCrossesOrigin(p.P.To(p.P + p.V*ds*t), p.Partner.P.To(p.Partner.P + p.V*ds*t), q.P);
// if (r.HasValue) t *= r.Value.T;
//}
p.P += p.V * ds * t;
p.P += new Vector(rng.NextDouble() - 0.5, rng.NextDouble() - 0.5);
p.V += a * ds;
p.V *= Math.Pow(0.5, ds);
}
};
animation.Add(new RectDesc(new Rect(10,10,w-20,w-20), Brushes.Black, Brushes.Transparent, 1, 2));
animation.StepActions.Add(step => {
sstep(step.TimeStep);
}, Lifetime.Immortal);
return animation;
}