draw-a-maze
by clean_blue_dot
HTML
<canvas style="margin: 0; padding: 0; background: black;" width="1861" height="683" id="clock-canvas"></canvas>
CSS
body
{
margin: 0;
padding: 0;
height: 100vh;
width: 100vw;
}
JavaScript
class OrderedPairQueue
{
constructor()
{
this.items = [];
}
enqueue(x, y)
{
this.items.push({x:x, y:y});
}
dequeue()
{
return this.items.shift();
}
peek()
{
return this.items[0];
}
isEmpty()
{
return (this.size() == 0);
}
size()
{
return this.items.length;
}
}
class DirectionsArray
{
constructor()
{
this.items = [];
}
add(d, x, y)
{
this.items[d] = {x:x, y:y};
}
get(d)
{
return this.items[d];
}
options()
{
return this.items.length;
}
}
const canvas = document.getElementById('clock-canvas');
const ctx = canvas.getContext('2d');
const TEST_NORTH = {X: 0, Y: -2};
const TEST_SOUTH = {X: 0, Y: 2};
const TEST_WEST = {X: -2, Y: 0};
const TEST_EAST = {X: 2, Y: 0};
const MOVE_NORTH = {X: 0, Y: -1};
const MOVE_SOUTH = {X: 0, Y: 1};
const MOVE_WEST = {X: -1, Y: 0};
const MOVE_EAST = {X: 1, Y: 0};
const EMPTY_CELL = 0;
const DOOR_CELL = 1;
const ROOM_CELL = 2;
function isEven(n)
{
return n % 2 == 0;
}
function drawSquare(ctx, x, y, size, color)
{
ctx.beginPath();
ctx.fillStyle = color;
ctx.moveTo(x, y);
ctx.lineTo(x + size, y);
ctx.lineTo(x + size, y + size);
ctx.lineTo(x, y + size);
ctx.lineTo(x, y);
ctx.fill();
ctx.closePath();
}
function startRender(ctx)
{
drawMaze(ctx);
}
function getRandom(min, max)
{
var out = Math.floor(Math.random() * (max - min) ) + min;
return out;
}
function drawMaze(ctx)
{
// fit size cells on available canvas size:
var cellSize = 12;
var cellsX = Math.floor(canvasSizeX / cellSize);
var cellsY = Math.floor(canvasSizeY / cellSize);
if (isEven(cellsX))
{
cellsX--;
}
if (isEven(cellsY))
{
cellsY--;
}
// set the centering offsets:
var offX = Math.floor((canvasSizeX - (cellsX * cellSize)) / 2);
var offY = Math.floor((canvasSizeY - (cellsY * cellSize)) / 2);
//...