static void Main(string[] args) { var result = RandomGrid.Generate(5); foreach (var i in result) { Console.WriteLine($"({i.P}, {i.Q})"); } }
/// <summary> /// 绘制连接图像。 /// </summary> /// <param name="n">矩阵边长。</param> public static void Draw(int n, TextBox log, Log WinBox) { logBox = log; // 生成路径。 log.AppendText("\r\n开始生成连接……"); bag = RandomGrid.Generate(n); log.AppendText("\r\n生成连接完成"); // 新建画布窗口。 log.AppendText("\r\n启动画布……"); Form2 matrix = new Form2(); matrix.StartPosition = FormStartPosition.Manual; matrix.Location = new Point(WinBox.Left - matrix.ClientRectangle.Width, WinBox.Top); matrix.Show(); log.AppendText("\r\n画布已启动,开始绘图……"); graphics = matrix.CreateGraphics(); // 获取绘图区域。 RectangleF rect = matrix.ClientRectangle; float unitX = rect.Width / (n + 1); float unitY = rect.Height / (n + 1); // 绘制点。 log.AppendText("\r\n绘制点……"); points = new PointF[n * n]; for (int row = 0; row < n; row++) { for (int col = 0; col < n; col++) { points[row * n + col] = new PointF(unitX * (col + 1), unitY * (row + 1)); graphics.FillEllipse(Brushes.Black, unitX * (col + 1), unitY * (row + 1), 5, 5); } } log.AppendText("\r\n绘制点完成"); // 绘制连接。 log.AppendText("\r\n开始绘制连接……"); connections = new List <Connection>(); foreach (Connection c in bag) { connections.Add(c); } timer = new Timer { Interval = 500 }; timer.Tick += DrawOneLine; timer.Start(); }