/// <summary> /// Utility functions that are not related to generating mazes. /// </summary> /// <param name="path">Path to export image to</param> /// <param name="m">The array of maze cells</param> /// <param name="size">Size, in pixels of cells</param> /// <param name="thick">Line thickness</param> public static void ExportToImage(string path, MazeGen.Maze m, int size, int thick) { Bitmap bit = new Bitmap(m.maze.GetLength(0) * size + thick * 2, m.maze.GetLength(1) * size + thick * 2); Graphics g = Graphics.FromImage(bit); System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.Purple, thick); for (int x = 0; x < m.maze.GetLength(0); x++) { for (int y = 0; y < m.maze.GetLength(1); y++) { if (m.maze[x, y].wallUp) { int X1 = x * size; int Y1 = y * size; int X2 = x * size + size; int Y2 = y * size; g.DrawLine(p, X1 + thick, Y1 + thick, X2 + thick, Y2 + thick); } if (m.maze[x, y].wallDown) { int X1 = x * size; int Y1 = y * size + size; int X2 = x * size + size; int Y2 = y * size + size; g.DrawLine(p, X1 + thick, Y1 + thick, X2 + thick, Y2 + thick); } if (m.maze[x, y].wallLeft) { int X1 = x * size; int Y1 = y * size; int X2 = x * size; int Y2 = y * size + size; g.DrawLine(p, X1 + thick, Y1 + thick, X2 + thick, Y2 + thick); } if (m.maze[x, y].wallRight) { int X1 = x * size + size; int Y1 = y * size; int X2 = x * size + size; int Y2 = y * size + size; g.DrawLine(p, X1 + thick, Y1 + thick, X2 + thick, Y2 + thick); } } //for y } // for x g.Save(); bit.Save(path); }
public void FillCanvas(Canvas canvas, MazeGen.Maze m) { int size = 25; Line l; Line l2 = new Line(); l2.X1 = MazeGen.Maze_Recursive_Backtracker.finishCellPoint.X * size; l2.X2 = MazeGen.Maze_Recursive_Backtracker.finishCellPoint.X * size + size; l2.Y1 = MazeGen.Maze_Recursive_Backtracker.finishCellPoint.Y * size; l2.Y2 = MazeGen.Maze_Recursive_Backtracker.finishCellPoint.Y * size + size; l2.Stroke = new SolidColorBrush(Colors.Red); canvas.Children.Add(l2); for (int x = 0; x < m.maze.GetLength(0); x++) { for (int y = 0; y < m.maze.GetLength(1); y++) { l = new Line(); l.Stroke = System.Windows.Media.Brushes.Black; l.StrokeThickness = 1; if (m.maze[x, y].wallUp) { l.X1 = x * size; l.Y1 = y * size; l.X2 = x * size + size; l.Y2 = y * size; canvas.Children.Add(l); } l = new Line(); l.Stroke = System.Windows.Media.Brushes.Black; l.StrokeThickness = 1; if (m.maze[x, y].wallDown) { l.X1 = x * size; l.Y1 = y * size + size; l.X2 = x * size + size; l.Y2 = y * size + size; canvas.Children.Add(l); } l = new Line(); l.Stroke = System.Windows.Media.Brushes.Black; l.StrokeThickness = 1; if (m.maze[x, y].wallLeft) { l.X1 = x * size; l.Y1 = y * size; l.X2 = x * size; l.Y2 = y * size + size; canvas.Children.Add(l); } l = new Line(); l.Stroke = System.Windows.Media.Brushes.Black; l.StrokeThickness = 1; if (m.maze[x, y].wallRight) { l.X1 = x * size + size; l.Y1 = y * size; l.X2 = x * size + size; l.Y2 = y * size + size; canvas.Children.Add(l); } } //for y } // for x }