-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeadEdge.html
More file actions
344 lines (291 loc) · 11.5 KB
/
LeadEdge.html
File metadata and controls
344 lines (291 loc) · 11.5 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<!DOCTYPE html>
<html>
<head>
<title>Lead Edge</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/GLTFLoader.js"></script> <!-- Add GLTFLoader -->
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/DRACOLoader.js"></script> <!-- Add DRACOLoader for GLTF compression -->
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/KTX2Loader.js"></script> <!-- Add KTX2Loader for texture compression -->
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/loaders/RGBELoader.js"></script> <!-- Add RGBELoader for environment maps -->
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/pmrem/PMREMGenerator.js"></script> <!-- Add PMREMGenerator for prefiltered environment maps -->
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/pmrem/PMREMCubeUVPacker.js"></script> <!-- Add PMREMCubeUVPacker for prefiltered environment maps -->
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/postprocessing/EffectComposer.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/postprocessing/RenderPass.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/postprocessing/ShaderPass.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/postprocessing/BloomPass.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/exporters/GLTFExporter.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.5.0-beta4/html2canvas.min.js"></script>
<style>
body {
background-image: url(leadedge2.jpg);
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
z-index: -1;
background-position: center center;
padding-top: 50px;
margin: 0;
height: 100vh;
display: flex;
//justify-content: center;
align-items: center;
flex-direction: column;
background-color: black;
}
#loading {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: #000;
color: #fff;
font-size: 24px;
}
#container {
margin-top: 50px;
display: flex;
align-items: flex-start;
justify-content: center;
height: 100%;
width: 100%;
}
#title {
color: white;
text-align: center;
}
#title h1 {
font-weight: bold;
}
canvas {
display: block;
}
#button-container {
display: flex;
justify-content: space-evenly;
margin-bottom: 20px;
}
button {
margin: 0 10px;
padding: 7px;
background-color: deepskyblue;
color: #fff;
font-size: 18px;
border: none;
border-radius: 5px;
cursor: pointer;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
transition: background-color 0.3s;
}
h2 {
color: white;
font-weight: bold;
}
h3 {
color: white;
font-weight: bold;
}
a {
text-decoration: underline;
text-decoration-color: deepskyblue;
}
#mazeSizeSlider {
display: block;
margin: 20px auto;
justify-content: center;
align-content: center;
width: 300px;
}
#controls {
display: flex;
flex-direction: column;
align-items: center;
padding: 25px;
}
#mazeSize {
margin-left: 10px;
color: white;
font-weight: bold;
}
#generationCount {
margin-left: 10px;
color: white;
font-weight: bold;
}
</style>
</head>
<body>
<div>
<div id="title" class="LeadEdgeHeader">
<h1>Lead Edge Algorithm <br><h3>(Sw)+(Sw^n)+(((b+b)*(a^2))/2)=r</h3></h1>
<h2>(A Maze Builder In Development) <div>
<label2 class="lea">
<a href="https://drive.google.com/file/d/16cv2e6i63LyRDt6fsKRehmYqh-AemQWr/view?usp=drivesdk" target="_blank">Access Documentation</a>
</div></h2>
</div>
<div id="controls">
<input id="mazeSizeSlider" type="range" min="10" max="200" value="50" class="slider">
<div id="mazeSize">Maze Size: 50</div>
<div id="generationCount">Generation Count: 0</div>
<br>
<br>
<div id="button-container">
<button id="generateMazeButton">Generate New Maze</button>
<button id="resetCameraButton">Reset Camera</button>
<button id="solveMazeButton">Solve Maze</button>
<button id="toggleWireframeButton">Toggle Wireframe</button>
<button id="exportButton">Export Maze as PNG</button>
<button id="exportGLBButton">Export GLB</button>
</div>
</div>
<div id="container">
<canvas id="canvas" width="875" height="875"></canvas>
</div>
</div>
<script>
const scene = new THREE.Scene();
const rendererWidth = 875;
const rendererHeight = 875;
const camera = new THREE.PerspectiveCamera(60, rendererWidth / rendererHeight, 0.1, 100000);
const renderer = new THREE.WebGLRenderer({
canvas: document.querySelector('#canvas'),
alpha: true
});
renderer.setSize(rendererWidth, rendererHeight);
const controls = new THREE.OrbitControls(camera, renderer.domElement);
camera.position.set(70, 30, 70);
controls.update();
let a = 50;
let b = 2;
let r = 0;
let wallColor = 0x00bfff; // DeepSkyBlue
let isWireframe = true;
let generationCount = 0;
// Add ambient light
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
// Add directional light
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
directionalLight.position.set(1, 1, 1);
scene.add(directionalLight);
function createWallSegment(x, z, isBranch = false) {
const geometry = new THREE.BoxGeometry(1, 1, 1);
let material;
if (isBranch) {
material = new THREE.MeshBasicMaterial({ color: 0x00bfff, wireframe: isWireframe });
} else {
material = new THREE.MeshBasicMaterial({ color: 0x00bfff, wireframe: isWireframe });
}
const wall = new THREE.Mesh(geometry, material);
wall.position.x = x;
wall.position.y = 0.5;
wall.position.z = z;
scene.add(wall);
}
function D1(a, b) {
while (scene.children.length > 0) {
scene.remove(scene.children[0]);
}
let entry = Math.floor(Math.random() * a);
let exit;
do {
exit = Math.floor(Math.random() * a);
} while (exit === entry);
for (let i = 0; i < a; i++) {
if (i !== entry) createWallSegment(i, 0);
if (i !== exit) createWallSegment(i, a - 1);
createWallSegment(0, i);
createWallSegment(a - 1, i);
}
const pathCells = new Set();
pathCells.add(`${entry},0`);
pathCells.add(`${exit},${a - 1}`);
let currentPos = { x: entry, y: 0 };
while (currentPos.y < a - 1) {
if (currentPos.x < exit) {
currentPos.x++;
} else if (currentPos.x > exit) {
currentPos.x--;
} else {
currentPos.y++;
}
pathCells.add(`${currentPos.x},${currentPos.y}`);
}
for (let i = 1; i < a - 1; i++) {
for (let j = 1; j < a - 1; j++) {
const key = `${i},${j}`;
if (i !== entry && i !== exit && !pathCells.has(key) && Math.random() < 0.5) {
createWallSegment(i, j, true);
}
}
}
}
function generateMaze() {
while (scene.children.length > 0) {
scene.remove(scene.children[0]);
}
r = ((b + b) * Math.pow(a, 2)) / 2;
D1(a, b);
generationCount++;
document.querySelector('#generationCount').textContent = 'Generation Count: ' + generationCount;
}
function resetCamera() {
camera.position.set(70, 30, 70);
controls.update();
}
function solveMaze() {
const path = scene.children.filter(object => object.material.color.getHex() === 0x00bfff);
path.forEach(segment => segment.material.color.set(0xffff00));
}
function toggleWireframe() {
isWireframe = !isWireframe;
generateMaze();
}
function exportCanvasToPNG() {
const canvas = document.querySelector('#canvas');
// Ensure that rendering is complete before capturing
renderer.render(scene, camera);
// Capture the canvas content as a data URL (PNG format)
const imgData = canvas.toDataURL('image/png');
// Create a link to download the image
const link = document.createElement('a');
link.href = imgData;
link.download = 'maze.png'; // Set the desired filename
link.click();
}
function exportGLB() {
const exporter = new THREE.GLTFExporter();
exporter.parse(scene, function (gltf) {
const glbBlob = new Blob([gltf], { type: 'application/octet-stream' });
const a = document.createElement('a');
a.href = URL.createObjectURL(glbBlob);
a.download = 'maze_model.glb';
a.click();
}, { binary: true });
}
document.querySelector('#generateMazeButton').addEventListener('click', generateMaze);
document.querySelector('#resetCameraButton').addEventListener('click', resetCamera);
document.querySelector('#solveMazeButton').addEventListener('click', solveMaze);
document.querySelector('#toggleWireframeButton').addEventListener('click', toggleWireframe);
document.querySelector('#exportButton').addEventListener('click', exportCanvasToPNG);
document.querySelector('#exportGLBButton').addEventListener('click', exportGLB);
document.querySelector('#mazeSizeSlider').addEventListener('input', function (event) {
a = event.target.value;
document.querySelector('#mazeSize').textContent = 'Maze Size: ' + a;
});
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
animate();
generateMaze();
</script>
</body>
</html>