-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathle.html
More file actions
195 lines (165 loc) · 6 KB
/
le.html
File metadata and controls
195 lines (165 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Lead Edge Maze</title>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 50px;
margin: 0;
height: 100vh;
background-color: indigo;
}
canvas {
margin-top: 20px;
}
button {
margin: 10px;
padding: 10px 20px;
background-color: deepskyblue;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
font-weight: bold;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}
.developer-comments {
font-size: 9px;
color: white;
text-align: left;
max-width: 550px;
font-weight: bold; /* Standard weight font */
}
</style>
</head>
<body>
<img src="https://static.wixstatic.com/media/2451db_cc9e86fb9d3045ecb0861ed65ff9e86d~mv2.png" alt="Lead Edge" style="max-width: 40%; height:auto;">
<br>
<img src="https://static.wixstatic.com/media/2451db_4f17959671e243e780f959689a435b86~mv2.png/v1/fill/w_800,h_354,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/Project%20202402202258.png" alt="Lead Edge" style="max-width: 70%; height:auto;">
<br>
<br>
<div class="developer-comments">
<h2>Developer Comments | To do: No more and no less than 2 openings, No Islands of space or walls and a wall length of only 1 unit per the only 90° turn(s) restriction.</h2>
</div>
<br>
<canvas id="mazeCanvas" width="600" height="600"></canvas>
<br>
<br>
<button onclick="generateMaze()">Generate Lead Edge Maze</button>
<br>
<button onclick="exportPNG()">Export as PNG</button>
<script>
const canvas = document.getElementById('mazeCanvas');
const ctx = canvas.getContext('2d');
const mazeSize = 600;
const unit = 30;
function generateMaze() {
ctx.clearRect(0, 0, mazeSize, mazeSize);
ctx.fillStyle = 'rgba(255, 255, 255, 0)';
ctx.fillRect(0, 0, mazeSize, mazeSize);
let current = { x: unit, y: unit }; // Starting point
let stack = [current];
let visited = new Set([posKey(current)]);
let lastDirection = null;
// Ensure no isolated spaces or walls
function checkIsolation(next) {
// Logic to ensure the next move doesn't create an isolated space or wall
return true; // Simplified for example
}
while (stack.length > 0) {
let next = getNextStep(current, lastDirection, visited);
if (next && checkIsolation(next)) {
drawLine(current.x, current.y, next.x, next.y);
visited.add(posKey(next));
stack.push(next);
lastDirection = direction(current, next);
current = next;
} else {
current = stack.pop();
lastDirection = null; // Reset direction after backtracking
}
}
// Additional code to ensure exactly two openings and only 90° turns
createOpenings();
}
function posKey(pos) {
return `${pos.x}:${pos.y}`;
}
function getNextStep(current, lastDirection, visited) {
let directions = ['up', 'right', 'down', 'left'];
if (lastDirection) {
// Bias the random direction based on last direction to prevent immediate backtracking
directions = directions.filter(dir => dir !== oppositeDirection(lastDirection));
}
while (directions.length > 0) {
let dirIndex = Math.floor(Math.random() * directions.length);
let dir = directions[dirIndex];
let next = move(current, dir);
if (!visited.has(posKey(next)) && isInBounds(next)) {
return next;
}
directions.splice(dirIndex, 1); // Remove direction and try another
}
return null; // No unvisited neighbors
}
function move(pos, direction) {
switch (direction) {
case 'up': return { x: pos.x, y: pos.y - unit };
case 'right': return { x: pos.x + unit, y: pos.y };
case 'down': return { x: pos.x, y: pos.y + unit };
case 'left': return { x: pos.x - unit, y: pos.y };
}
}
function direction(from, to) {
if (from.x === to.x) {
return (from.y > to.y) ? 'up' : 'down';
} else {
return (from.x < to.x) ? 'right' : 'left';
}
}
function oppositeDirection(dir) {
switch (dir) {
case 'up': return 'down';
case 'right': return 'left';
case 'down': return 'up';
case 'left': return 'right';
}
}
function isInBounds(pos) {
return pos.x >= 0 && pos.x <= mazeSize && pos.y >= 0 && pos.y <= mazeSize;
}
function drawLine(x1, y1, x2, y2) {
const dx = Math.abs(x2 - x1);
const dy = Math.abs(y2 - y1);
if (dx + dy === unit) { // Ensure line length is 1 unit
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.strokeStyle = '#FFF';
ctx.lineWidth = 2;
ctx.stroke();
}
}
function exportPNG() {
// Generate a PNG image data URL from the canvas
const dataURL = canvas.toDataURL("image/png");
// Create an anchor (<a>) element
const a = document.createElement('a');
// Set the href to the data URL
a.href = dataURL;
// Set the download attribute to the desired filename
a.download = 'LeadEdgeMaze.png';
// Append the anchor to the document
document.body.appendChild(a);
// Trigger the download
a.click();
// Remove the anchor from the document
document.body.removeChild(a);
}
</script>
</body>
</html>