void AddSubNodes(NodeBase node, int depth, int maxDepth)
        {
            if (depth >= maxDepth)
            {
                return;
            }

            int children = rand.Next(1, maxDepth - depth + 3);

            double size = Math.Max(0.2, rand.NextDouble() * children / 4);

            node.Mass   += size;
            node.Charge += size;

            for (int i = 0; i < children; i++)
            {
                Color  col  = ColourTools.GetRainbowColor(depth, 0, maxDepth);
                double mass = 0.5;
                Point  p    = rand.NextPoint(node.Position, 50);

                NodeBase child = new Node(p, mass, col);
                myNodeControl.AddNode(child);

                EdgeBase edge = new Edge(node, child);
                myNodeControl.AddEdge(edge);

                AddSubNodes(child, depth + 1, maxDepth);
            }
        }
        public void AddGrid(int width, int height, bool tangled, bool randomMass)
        {
            Point origin = myNodeControl.Centre;

            int total = width * height;

            NodeBase[,] grid = new NodeBase[width, height];
            int count = 0;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Color  col  = ColourTools.GetRainbowColor(count, 0, total);
                    double mass = 0.5;
                    if (randomMass)
                    {
                        mass = 0.5 + rand.NextDouble() * 2;
                    }

                    Point p;
                    if (tangled)
                    {
                        p = rand.NextPoint(origin, 400);
                    }
                    else
                    {
                        p = new Point(origin.X + x * 60, origin.Y + y * 60);
                    }

                    NodeBase n = new Node(p, mass, col);
                    grid[x, y] = n;
                    myNodeControl.AddNode(n);
                    count++;

                    if (x > 0)
                    {
                        NodeBase other = grid[x - 1, y];

                        EdgeBase edge = new Edge(n, other);
                        myNodeControl.AddEdge(edge);
                    }

                    if (y > 0)
                    {
                        NodeBase other = grid[x, y - 1];

                        EdgeBase edge = new Edge(n, other);
                        myNodeControl.AddEdge(edge);
                    }
                }
            }
        }
        public void AddTree(int maxDepth)
        {
            Point origin = myNodeControl.Centre;

            Color    col  = ColourTools.GetRainbowColor(0, 0, maxDepth);
            double   mass = 2;
            NodeBase node = new Node(origin, mass, col);

            myNodeControl.AddNode(node);

            AddSubNodes(node, 0, maxDepth);
        }
        public void AddSpiral(int count)
        {
            Point       origin = myNodeControl.Centre;
            SpiralMaker spiral = new SpiralMaker(origin, 5, 200, 200);

            NodeBase parent = new Node(origin, 0.5, Colors.Green);

            myNodeControl.AddNode(parent);

            for (int i = 0; i < count; i++)
            {
                Color  col  = ColourTools.GetRainbowColor(i, 0, count);
                double mass = 0.5;

                Point p = spiral.NextPoint();

                NodeBase child = new Node(p, mass, col);
                myNodeControl.AddNode(child);

                EdgeBase edge = new Edge(parent, child);
                myNodeControl.AddEdge(edge);
            }
        }
Exemplo n.º 5
0
 public Edge(NodeBase from, NodeBase to)
     : this(from, to, ColourTools.Average(from.Colour, to.Colour))
 {
 }