@Brandon Boone
I do some updates for your code as below:
PathSegmentCollection bbb = new PathSegmentCollection();
PathFigure pf = new PathFigure();
int levelNew;
double oldX = 0, oldY = 0;
double newX = 0, newY = 0;
public Shape PrintTree()
{
Path treePath = new Path();
treePath.Stroke = Brushes.Black;
treePath.StrokeThickness = 5;
MakeTree();
PathGeometry pg = new PathGeometry()
{
Figures = new PathFigureCollection()
{
new PathFigure()
{
IsClosed = false,
StartPoint = new Point(50,0),
Segments = pf.Segments
},
new PathFigure()
{
IsClosed = false,
StartPoint = new Point(oldX,oldY),
Segments = bbb
}
}
};
treePath.Data = pg;
return treePath;
}
public void MakeTree()
{
double direction = Math.PI * 0.5D;
double length = 100;
int level = 1;
double aScale = 0.9;
double bScale = 0.5;
Insert(pf, 50, 50, direction, 45, 45, level, length, aScale, bScale);
}
void Insert(PathFigure pf, double x, double y, double direction, double angleA, double angleB, int level, double length, double aScale, double bScale)
{
if (length < 0.1)
return;
x += length * Math.Cos(direction);
y += length * Math.Sin(direction);
levelNew = level;
LineSegment line = new LineSegment(new Point(x, y), true);
pf.Segments.Add(line);
if (level > 0)
{
Insert(pf, x, y, direction + angleA, angleA, angleB, level-1, length * aScale, aScale, bScale);
if (levelNew >= 0)
{
oldX = x;
oldY = y;
newX = length * Math.Cos(direction + angleB);
newY = length * Math.Sin(direction + angleB);
bbb.Add(new LineSegment(new Point(newX, newY), true));
levelNew--;
}
}
}
The result picture is:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.