ASCII Maze 2

by eulomelo

HTML

<!DOCTYPE HTML>
<html>

  <head>
    <title>ASCII Maze</title>
    <meta charset="UTF-8">
    <style>
      body {
        display: grid;
        place-items: center;
      }

      #Maze {
        font-family: monospace;
        font-size: 5px;
      }

    </style>
  </head>

  <body>
    <h1> ASCII Maze </h1>
    <div id="Maze"></div>
  </body>
  <script>
    let canvas = document.getElementById("Maze");
    wall = "⬛";
    pass = "⬜";

    //Makes maze array into string
    function string2Darray(array) {
      let arrayString = "";
      for (let i = 0; i < array.length; i++) {
        for (let j = 0; j < array[i].length; j++) {
          arrayString += array[i][j];
        }
        arrayString += "\n";
      }
      return arrayString;
    }
    //helpers
    function north(x, y, maze) {
      maze[y][x - 1] = pass;
      maze[y][x + 1] = pass;
      maze[y + 1][x] = pass;
      maze[y + 1][x - 1] = pass;
      maze[y + 1][x + 1] = pass;
    }

    function west(x, y, maze) {
      maze[y - 1][x] = pass;
      maze[y + 1][x] = pass;
      maze[y][x + 1] = pass;
      maze[y - 1][x + 1] = pass;
      maze[y + 1][x + 1] = pass;
    }

    function nowhere(x, y, maze) {
      maze[y - 1][x] = pass;
      maze[y + 1][x] = pass;
      maze[y][x + 1] = pass;
      maze[y - 1][x + 1] = pass;
      maze[y + 1][x + 1] = pass;
      maze[y][x - 1] = pass;
      maze[y + 1][x - 1] = pass;
    }

    //Makes maze array 
    function makeMaze(size) {
      maze = [];
      for (let i = 0; i < size; i++) {
        row = [];
        for (let j = 0; j < size; j++) {
          row.push(wall);
        }
        maze.push(row);
      }

      for (let i = 0; i < size / 3; i++) {
        for (let j = 0; j < size / 3; j++) {
          let x = 3 * i + 1;
          let y = 3 * j + 1;
          maze[y][x] = pass;
          let random = Math.random();
          if (random < 0.45) {
            north(x, y, maze);
          } else if (random < 0.9) {
            west(x, y, maze);
  ...