Update index.html
Browse files- index.html +44 -26
index.html
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<html>
|
3 |
<head>
|
4 |
<meta charset="utf-8">
|
5 |
-
<title>Recursive Polygons in 3D</title>
|
6 |
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
|
7 |
<script src="https://unpkg.com/aframe-environment-component/dist/aframe-environment-component.min.js"></script>
|
8 |
<style>
|
@@ -15,32 +15,50 @@
|
|
15 |
<body>
|
16 |
<a-scene>
|
17 |
<a-entity environment="preset: forest"></a-entity>
|
18 |
-
|
19 |
-
<!-- Recursive Polygon Component -->
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
height: 0.5; // Polygon height
|
26 |
-
x: 0; // X-position
|
27 |
-
y: 0; // Y-position
|
28 |
-
z: -5 // Z-position
|
29 |
-
"></a-entity>
|
30 |
-
|
31 |
-
<!-- Math Function -->
|
32 |
-
<a-entity math-function="
|
33 |
-
func: sin(x^2+y^2)/sqrt(x^2+y^2); // Math function to evaluate
|
34 |
-
xmin: -5; xmax: 5; // Range of x-values
|
35 |
-
ymin: -5; ymax: 5; // Range of y-values
|
36 |
-
xstep: 0.2; ystep: 0.2; // Step size for x and y
|
37 |
-
scale: 0.5; // Scale factor
|
38 |
-
color: #8CEEEF; // Function color
|
39 |
-
height: 0.1; // Function height
|
40 |
-
z: -5 // Z-position
|
41 |
-
"></a-entity>
|
42 |
-
|
43 |
<a-entity camera position="0 1.6 0" look-controls wasd-controls></a-entity>
|
44 |
</a-scene>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
</body>
|
46 |
</html>
|
|
|
2 |
<html>
|
3 |
<head>
|
4 |
<meta charset="utf-8">
|
5 |
+
<title>Recursive Polygons in 3D with Snowflakes</title>
|
6 |
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
|
7 |
<script src="https://unpkg.com/aframe-environment-component/dist/aframe-environment-component.min.js"></script>
|
8 |
<style>
|
|
|
15 |
<body>
|
16 |
<a-scene>
|
17 |
<a-entity environment="preset: forest"></a-entity>
|
18 |
+
|
19 |
+
<!-- Existing Recursive Polygon Component -->
|
20 |
+
<!-- ... Your existing entities ... -->
|
21 |
+
|
22 |
+
<!-- Snowflakes Component -->
|
23 |
+
<a-entity id="snowflakes"></a-entity>
|
24 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
<a-entity camera position="0 1.6 0" look-controls wasd-controls></a-entity>
|
26 |
</a-scene>
|
27 |
+
|
28 |
+
<script>
|
29 |
+
AFRAME.registerComponent('snowflake', {
|
30 |
+
init: function() {
|
31 |
+
this.el.setAttribute('geometry', {
|
32 |
+
primitive: 'sphere',
|
33 |
+
radius: 0.05
|
34 |
+
});
|
35 |
+
this.el.setAttribute('material', { color: '#FFF' });
|
36 |
+
|
37 |
+
// Set initial position
|
38 |
+
this.el.object3D.position.set(
|
39 |
+
(Math.random() - 0.5) * 20,
|
40 |
+
5 + Math.random() * 5,
|
41 |
+
(Math.random() - 0.5) * 20
|
42 |
+
);
|
43 |
+
|
44 |
+
// Set velocity
|
45 |
+
this.velocity = new THREE.Vector3(0, -0.05, 0);
|
46 |
+
},
|
47 |
+
tick: function() {
|
48 |
+
this.el.object3D.position.add(this.velocity);
|
49 |
+
if (this.el.object3D.position.y <= 0) {
|
50 |
+
this.el.parentNode.removeChild(this.el); // Remove snowflake when it hits the ground
|
51 |
+
}
|
52 |
+
}
|
53 |
+
});
|
54 |
+
|
55 |
+
// Generate snowflakes
|
56 |
+
setInterval(() => {
|
57 |
+
let sceneEl = document.querySelector('a-scene');
|
58 |
+
let snowflakeEl = document.createElement('a-entity');
|
59 |
+
snowflakeEl.setAttribute('snowflake', '');
|
60 |
+
sceneEl.appendChild(snowflakeEl);
|
61 |
+
}, 100);
|
62 |
+
</script>
|
63 |
</body>
|
64 |
</html>
|