Update index.html
Browse files- index.html +34 -16
index.html
CHANGED
@@ -12,7 +12,7 @@
|
|
12 |
<a-entity id="camera" camera look-controls wasd-controls></a-entity>
|
13 |
</a-entity>
|
14 |
<a-sky color="#0000ff"></a-sky>
|
15 |
-
<a-entity id="
|
16 |
</a-scene>
|
17 |
|
18 |
<script>
|
@@ -21,28 +21,46 @@
|
|
21 |
window.addEventListener('keydown', (event) => {
|
22 |
const key = event.key.toLowerCase();
|
23 |
if (key.length === 1 && /^[a-z]+$/.test(key)) {
|
24 |
-
this.
|
25 |
}
|
26 |
});
|
27 |
},
|
28 |
-
|
29 |
-
|
30 |
-
const
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
}
|
38 |
});
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
44 |
}
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
</script>
|
47 |
</body>
|
48 |
</html>
|
|
|
12 |
<a-entity id="camera" camera look-controls wasd-controls></a-entity>
|
13 |
</a-entity>
|
14 |
<a-sky color="#0000ff"></a-sky>
|
15 |
+
<a-entity id="objectsContainer"></a-entity>
|
16 |
</a-scene>
|
17 |
|
18 |
<script>
|
|
|
21 |
window.addEventListener('keydown', (event) => {
|
22 |
const key = event.key.toLowerCase();
|
23 |
if (key.length === 1 && /^[a-z]+$/.test(key)) {
|
24 |
+
this.generateObject(key);
|
25 |
}
|
26 |
});
|
27 |
},
|
28 |
+
|
29 |
+
generateObject: function (key) {
|
30 |
+
const objectsContainer = document.querySelector('#objectsContainer');
|
31 |
+
const object = document.createElement('a-entity');
|
32 |
+
|
33 |
+
// Set object properties and components
|
34 |
+
object.setAttribute('geometry', {
|
35 |
+
primitive: 'box',
|
36 |
+
width: 1,
|
37 |
+
height: 1,
|
38 |
+
depth: 1
|
39 |
+
});
|
40 |
+
object.setAttribute('material', { color: getRandomColor() });
|
41 |
+
object.setAttribute('position', getRandomPosition());
|
42 |
+
|
43 |
+
objectsContainer.appendChild(object);
|
44 |
}
|
45 |
});
|
46 |
|
47 |
+
// Helper function to generate random color
|
48 |
+
function getRandomColor() {
|
49 |
+
const letters = '0123456789ABCDEF';
|
50 |
+
let color = '#';
|
51 |
+
for (let i = 0; i < 6; i++) {
|
52 |
+
color += letters[Math.floor(Math.random() * 16)];
|
53 |
}
|
54 |
+
return color;
|
55 |
+
}
|
56 |
+
|
57 |
+
// Helper function to generate random position
|
58 |
+
function getRandomPosition() {
|
59 |
+
const x = Math.random() * 10 - 5;
|
60 |
+
const y = Math.random() * 10 - 5;
|
61 |
+
const z = Math.random() * 10 - 5;
|
62 |
+
return `${x} ${y} ${z}`;
|
63 |
+
}
|
64 |
</script>
|
65 |
</body>
|
66 |
</html>
|