Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
- return;
- string filename = openFileDialog1.FileName;
- StreamReader R = new StreamReader(filename);
- myGraph = new Graph(R);
- input_nVertex = myGraph.nVerts;
- pictureBox1.Image = (Image)new Bitmap(pictureBox1.Width, pictureBox1.Height);
- Graphics g = Graphics.FromImage(pictureBox1.Image);
- Pen p = new Pen(Color.Black, 3);
- //float heightSeparation = pictureBox1.Height / myGraph.nVerts;
- //float widthSeparation = pictureBox1.Width / myGraph.nVerts;
- float circleSeparation = Convert.ToSingle(2 * Math.PI) / myGraph.nVerts;
- float centerX = pictureBox1.Width / 2;
- float centerY = pictureBox1.Height / 2;
- //g.TranslateTransform(centerX, centerY);
- for (int i = 1; i <= myGraph.nVerts; i++)
- {
- //PointF startPoint = new PointF(i * widthSeparation, i * heightSeparation);
- //PointF endPoint = new PointF(startPoint.X - 15, startPoint.Y - 15);
- //PointF centerPoint = new PointF(Convert.ToSingle(15 * Math.Cos((2 * Math.PI) / myGraph.nVerts) * i), Convert.ToSingle(15 * Math.Sin((2 * Math.PI) / myGraph.nVerts) * i));
- PointF centerPoint = new PointF(170 * Convert.ToSingle(Math.Cos(circleSeparation * i)) + centerX, 170 * Convert.ToSingle(Math.Sin (circleSeparation * i)) + centerY);
- g.FillEllipse(Brushes.White, centerPoint.X - 25, centerPoint.Y - 25, 50, 50);
- g.DrawEllipse(p, centerPoint.X - 25, centerPoint.Y - 25, 50, 50);
- Point stringPoint = new Point(Convert.ToInt32(centerPoint.X - 13), Convert.ToInt32(centerPoint.Y - 13));
- g.DrawString(myGraph.vertexList[i - 1].label, new Font("Arial", 20), Brushes.Black, stringPoint);
- myGraph.vertexList[i - 1].centerPoint = centerPoint;
- }
- for (int i = 0; i < myGraph.nVerts; i++)
- {
- for (int j = 0; j < myGraph.nVerts; j++)
- {
- if (myGraph.adjMatrix[i][j] != 0)
- {
- PointF startPosition = myGraph.vertexList[i].centerPoint;
- PointF endPosition = myGraph.vertexList[j].centerPoint;
- g.DrawLine(Pens.Black, startPosition, endPosition);
- g.FillEllipse(Brushes.White, startPosition.X - 25, startPosition.Y - 25, 50, 50);
- g.DrawEllipse(p, startPosition.X - 25, startPosition.Y - 25, 50, 50);
- g.FillEllipse(Brushes.White, endPosition.X - 25, endPosition.Y - 25, 50, 50);
- g.DrawEllipse(p, endPosition.X - 25, endPosition.Y - 25, 50, 50);
- PointF stringPoint = new PointF(Convert.ToInt32(startPosition.X - 13), Convert.ToInt32(startPosition.Y - 13));
- g.DrawString(myGraph.vertexList[i].label, new Font("Arial", 20), Brushes.Black, stringPoint);
- stringPoint = new PointF(Convert.ToInt32(endPosition.X - 13), Convert.ToInt32(endPosition.Y - 13));
- g.DrawString(myGraph.vertexList[j].label, new Font("Arial", 20), Brushes.Black, stringPoint);
- stringPoint = new PointF((startPosition.X + endPosition.X) / 2, (startPosition.Y + endPosition.Y) / 2);
- g.DrawString(myGraph.adjMatrix[i][j].ToString(), new Font("Arial", 20), Brushes.Black, stringPoint);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement