Update index.html
Browse files- index.html +27 -16
index.html
CHANGED
@@ -23,44 +23,56 @@
|
|
23 |
<!-- Clouds will be added dynamically -->
|
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:
|
34 |
});
|
35 |
this.el.setAttribute('material', { color: '#FFF' });
|
36 |
|
37 |
-
// Randomly position within a unit cube centered at the origin
|
38 |
this.el.object3D.position.set(
|
39 |
Math.random() - 0.5,
|
40 |
-
|
41 |
Math.random() - 0.5
|
42 |
);
|
43 |
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
46 |
},
|
47 |
tick: function() {
|
48 |
this.el.object3D.position.add(this.velocity);
|
49 |
if (this.el.object3D.position.y <= -0.5) {
|
50 |
-
this.el.
|
|
|
51 |
}
|
52 |
}
|
53 |
});
|
54 |
|
55 |
-
function createSnowflakeCloud(x, y, z) {
|
56 |
let cloud = document.createElement('a-entity');
|
57 |
cloud.object3D.position.set(x, y, z);
|
58 |
|
59 |
-
|
60 |
-
let
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
64 |
|
65 |
document.querySelector('a-scene').appendChild(cloud);
|
66 |
}
|
@@ -68,13 +80,12 @@
|
|
68 |
// Create a grid of 9 snowflake clouds
|
69 |
for (let x = -10; x <= 10; x += 10) {
|
70 |
for (let z = -10; z <= 10; z += 10) {
|
71 |
-
createSnowflakeCloud(x, 5, z);
|
72 |
}
|
73 |
}
|
74 |
|
75 |
// Create a larger central cloud
|
76 |
-
createSnowflakeCloud(0, 8, 0);
|
77 |
-
|
78 |
</script>
|
79 |
</body>
|
80 |
-
</html>
|
|
|
23 |
<!-- Clouds will be added dynamically -->
|
24 |
|
25 |
<a-entity camera position="0 1.6 0" look-controls wasd-controls></a-entity>
|
26 |
+
<a-plane position="0 0 0" rotation="-90 0 0" width="100" height="100" color="#FFF"></a-plane>
|
27 |
</a-scene>
|
28 |
|
29 |
<script>
|
30 |
AFRAME.registerComponent('snowflake', {
|
31 |
+
schema: {
|
32 |
+
size: { type: 'number', default: 0.1 }
|
33 |
+
},
|
34 |
init: function() {
|
35 |
+
let size = this.data.size;
|
36 |
+
|
37 |
this.el.setAttribute('geometry', {
|
38 |
primitive: 'sphere',
|
39 |
+
radius: size
|
40 |
});
|
41 |
this.el.setAttribute('material', { color: '#FFF' });
|
42 |
|
|
|
43 |
this.el.object3D.position.set(
|
44 |
Math.random() - 0.5,
|
45 |
+
0,
|
46 |
Math.random() - 0.5
|
47 |
);
|
48 |
|
49 |
+
this.velocity = new THREE.Vector3(
|
50 |
+
(Math.random() - 0.5) * 0.01, // Random wind effect
|
51 |
+
-0.01, // Falling speed
|
52 |
+
(Math.random() - 0.5) * 0.01 // Random wind effect
|
53 |
+
);
|
54 |
},
|
55 |
tick: function() {
|
56 |
this.el.object3D.position.add(this.velocity);
|
57 |
if (this.el.object3D.position.y <= -0.5) {
|
58 |
+
this.el.object3D.position.y = -0.5; // Accumulate on the ground
|
59 |
+
this.velocity.set(0, 0, 0); // Stop movement when it hits the ground
|
60 |
}
|
61 |
}
|
62 |
});
|
63 |
|
64 |
+
function createSnowflakeCloud(x, y, z, numParticles) {
|
65 |
let cloud = document.createElement('a-entity');
|
66 |
cloud.object3D.position.set(x, y, z);
|
67 |
|
68 |
+
for (let i = 0; i < numParticles; i++) {
|
69 |
+
let size = Math.random() * 0.1 + 0.05; // Random size between 0.05 and 0.15
|
70 |
+
setTimeout(() => {
|
71 |
+
let snowflakeEl = document.createElement('a-entity');
|
72 |
+
snowflakeEl.setAttribute('snowflake', 'size', size);
|
73 |
+
cloud.appendChild(snowflakeEl);
|
74 |
+
}, i * 100);
|
75 |
+
}
|
76 |
|
77 |
document.querySelector('a-scene').appendChild(cloud);
|
78 |
}
|
|
|
80 |
// Create a grid of 9 snowflake clouds
|
81 |
for (let x = -10; x <= 10; x += 10) {
|
82 |
for (let z = -10; z <= 10; z += 10) {
|
83 |
+
createSnowflakeCloud(x, 5, z, 50); // Increase the number of particles per cloud
|
84 |
}
|
85 |
}
|
86 |
|
87 |
// Create a larger central cloud
|
88 |
+
createSnowflakeCloud(0, 8, 0, 100);
|
|
|
89 |
</script>
|
90 |
</body>
|
91 |
+
</html>
|