本文整理汇总了C#中Path.AddLine方法的典型用法代码示例。如果您正苦于以下问题:C# Path.AddLine方法的具体用法?C# Path.AddLine怎么用?C# Path.AddLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Path
的用法示例。
在下文中一共展示了Path.AddLine方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBorder
/// <summary>
/// 向拼图碎片的路径中添加一条边,路径的当前节点总是在起始点。
/// </summary>
/// <param name="path">路径。</param>
/// <param name="startPoint">边的起始点。</param>
/// <param name="endPoint">边的结束点。</param>
/// <param name="randoms">该边的凹凸性。</param>
/// <param name="border">与该条边相关的一组随机数,范围都是 [0, 1)。</param>
protected override void AddBorder(Path path, Vector2 startPoint, Vector2 endPoint,
bool border, float[] randoms)
{
Vector2 sp = Vector2.Lerp(startPoint, endPoint, 1f / 3);
Vector2 ep = Vector2.Lerp(startPoint, endPoint, 2f / 3);
path.AddLine(sp);
double angle = Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X) * 180 / Math.PI + 180;
float len = Vector2.Distance(startPoint, endPoint) / 6;
path.AddArc(ep, new Size2F(len, len), (float)angle,
border ? SweepDirection.CounterClockwise : SweepDirection.Clockwise, ArcSize.Small);
path.AddLine(endPoint);
}
示例2: AddBorder
/// <summary>
/// 向拼图碎片的路径中添加一条边,路径的当前节点总是在起始点。
/// </summary>
/// <param name="path">路径。</param>
/// <param name="startPoint">边的起始点。</param>
/// <param name="endPoint">边的结束点。</param>
/// <param name="randoms">该边的凹凸性。</param>
/// <param name="border">与该条边相关的一组随机数,范围都是 [0, 1)。</param>
protected override void AddBorder(Path path, Vector2 startPoint, Vector2 endPoint,
bool border, float[] randoms)
{
// 贝塞尔曲线的起始和结束点。
float rate1 = 1f / 3 + randoms[0] / 12;
Vector2 sp = Vector2.Lerp(startPoint, endPoint, rate1);
Vector2 ep = Vector2.Lerp(startPoint, endPoint, 1 - rate1);
// 贝塞尔曲线的控制点。
float rate2 = rate1 - randoms[1] / 4;
Vector2 c1 = Vector2.Lerp(startPoint, endPoint, rate2);
Vector2 c2 = Vector2.Lerp(startPoint, endPoint, 1 - rate2);
// 与边框垂直的向量。
Vector2 cross = new Vector2(endPoint.Y - startPoint.Y, startPoint.X - endPoint.X);
if (!border)
{
cross.X *= -1;
cross.Y *= -1;
}
cross *= 1f / 4 + randoms[2] / 8;
path.AddLine(sp);
path.AddBezier(ep, c1 + cross, c2 + cross);
path.AddLine(endPoint);
}
示例3: AddBorder
/// <summary>
/// 向拼图碎片的路径中添加一条边,路径的当前节点总是在起始点。
/// </summary>
/// <param name="path">路径。</param>
/// <param name="startPoint">边的起始点。</param>
/// <param name="endPoint">边的结束点。</param>
/// <param name="randoms">该边的凹凸性。</param>
/// <param name="border">与该条边相关的一组随机数,范围都是 [0, 1)。</param>
protected virtual void AddBorder(Path path, Vector2 startPoint, Vector2 endPoint,
bool border, float[] randoms)
{
path.AddLine(endPoint);
}
示例4: GererateJigsawShape
/// <summary>
/// 生成拼图形状。
/// </summary>
public void GererateJigsawShape()
{
// 拼图尺寸。
float width = Size.Width;
float height = Size.Height;
// 拼图碎片的尺寸。
float pWidth = width / horizontalDimension;
float pHeight = height / verticalDimension;
// 拼图碎片的随机化尺寸。
float rWidth = pWidth * randomization / 3;
float rHeight = pHeight * randomization / 3;
float x, y;
// 最后一行节点。
Vector2[] corners = new Vector2[horizontalDimension + 1];
Vector2 lastPoint = new Vector2();
// 最后一行的边凹凸性。
bool[] borders = new bool[horizontalDimension + 1];
bool lastBorder = false;
// 最后一行的随机数。
float[][] values = new float[horizontalDimension + 1][];
float[] lastValue = null;
for (int i = 0; i <= this.verticalDimension; i++)
{
for (int j = 0; j <= this.horizontalDimension; j++)
{
y = pHeight * i;
if (i > 0 && i < this.verticalDimension && rHeight != 0f)
{
y += (float)((RandomExt.NextDouble() * 2 - 1) * rHeight);
}
x = pWidth * j;
if (j > 0 && j < horizontalDimension && rWidth != 0f)
{
x += (float)((RandomExt.NextDouble() * 2 - 1) * rWidth);
}
Vector2 currentPoint = new Vector2(x, y);
if (i == 0)
{
corners[j] = currentPoint;
}
else if (j == 0)
{
lastPoint = currentPoint;
}
else
{
// 将拼图碎片放置在国际象棋盘上,每片会分别对应黑色和白色。
bool isBlack = (i + j) % 2 == 0;
Path path = new Path(corners[j], isBlack);
// 逆时针添加边。
// 顶边。
if (i == 1)
{
path.AddLine(corners[j - 1]);
}
else
{
AddBorder(path, corners[j], corners[j - 1], !borders[j], values[j]);
}
// 左边。
if (j == 1)
{
path.AddLine(lastPoint);
}
else
{
AddBorder(path, corners[j - 1], lastPoint, !lastBorder, lastValue);
}
// 底边。
if (i == verticalDimension)
{
path.AddLine(currentPoint);
}
else
{
borders[j] = RandomExt.NextBoolean();
values[j] = GenerateRandom();
AddBorder(path, lastPoint, currentPoint, borders[j], values[j]);
}
// 右边。
if (j == horizontalDimension)
{
path.AddLine(corners[j]);
}
else
{
lastBorder = RandomExt.NextBoolean();
lastValue = GenerateRandom();
AddBorder(path, currentPoint, corners[j], lastBorder, lastValue);
}
this.paths.Add(path);
// 计算形状的重心。
Vector2 c1 = SharpDXUtility.GetCenter(corners[j - 1], corners[j], lastPoint);
Vector2 c2 = SharpDXUtility.GetCenter(corners[j], lastPoint, currentPoint);
float w1 = SharpDXUtility.Area(corners[j - 1], corners[j], lastPoint);
float w2 = SharpDXUtility.Area(corners[j], lastPoint, currentPoint);
path.Weight = w1 + w2;
//.........这里部分代码省略.........