I am trying to code a function that takes in a string of words and turns it in to a fractal word tree . My tree look just weird and I do not how to turn a string into a shape
here is what I have :
public Shape PrintTree(Brush customColor)
{
Path treePath = new Path();
// treePath.Fill = customColor;
treePath.Stroke = Brushes.Black;
treePath.StrokeThickness = 5;
PathFigure pf = new PathFigure();
//
pf.IsClosed = false;
MakeTree( pf);
// PreOrderTraversing(_root, pf);
PathGeometry pg = new PathGeometry();
pg.Figures.Add(pf);
treePath.Data = pg;
return treePath;
}
public void MakeTree(PathFigure pf)
{
pf.StartPoint = new Point(0, 0);
pf.Segments.Add(new LineSegment(new Point(0, 10), true));
double direction = Math.PI * 0.5D;
double length = 100;
int level =1;
double aScale = 0.9;
double bScale = 0.5;
Insert(pf, 0, 10, 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);
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);
Insert(pf, x, y, direction + angleB, angleA, angleB, level - 1, length * bScale, aScale, bScale);
}
}
