Ejemplo n.º 1
0
        public override void Initialize()
        {
            int numNodes = 50;
            int numEdges = 50;

            // Initialize, and create a layer for the edges (always underneath the nodes)
            PLayer nodeLayer = Canvas.Layer;
            PLayer edgeLayer = new PLayer();

            Canvas.Root.AddChild(edgeLayer);
            Canvas.Camera.AddLayer(0, edgeLayer);
            Random rnd = new Random();

            // Create some random nodes
            // Each node's Tag has an ArrayList used to store associated edges
            for (int i = 0; i < numNodes; i++)
            {
                float  x    = (float)(ClientSize.Width * rnd.NextDouble());
                float  y    = (float)(ClientSize.Height * rnd.NextDouble());
                P3Path node = P3Path.CreateEllipse(x, y, 20, 20);

                node.Tag = new ArrayList();
                nodeLayer.AddChild(node);
            }

            // Create some random edges
            // Each edge's Tag has an ArrayList used to store associated nodes
            for (int i = 0; i < numEdges; i++)
            {
                int n1 = rnd.Next(numNodes);
                int n2 = n1;
                while (n2 == n1)
                {
                    n2 = rnd.Next(numNodes);                      // Make sure we have two distinct nodes.
                }

                PNode  node1 = nodeLayer[n1];
                PNode  node2 = nodeLayer[n2];
                P3Path edge  = P3Path.CreateLine((node1.Bounds.Left + node1.Bounds.Right) / 2, (node1.Bounds.Top + node1.Bounds.Bottom) / 2,
                                                 (node2.Bounds.Left + node2.Bounds.Right) / 2, (node2.Bounds.Top + node2.Bounds.Bottom) / 2);

                ((ArrayList)node1.Tag).Add(edge);
                ((ArrayList)node2.Tag).Add(edge);
                edge.Tag = new ArrayList();
                ((ArrayList)edge.Tag).Add(node1);
                ((ArrayList)edge.Tag).Add(node2);

                edgeLayer.AddChild(edge);
            }

            // Create event handler to move nodes and update edges
            nodeLayer.AddInputEventListener(new NodeDragHandler());
        }
Ejemplo n.º 2
0
        protected void CreateLines()
        {
            // Create a bunch of lines
            for (int x = 0; x < 1000; x += 10)
            {
                P3Path line = P3Path.CreateLine(10, 60, 10 + x, 200);
                line.Pen = new Pen(Color.Orange, 0);
                canvas.Layer.AddChild(line);

                line     = P3Path.CreateLine(500, 60, 1000 - x, 200);
                line.Pen = new Pen(Color.Purple, 0);
                canvas.Layer.AddChild(line);
            }
        }