awacke1 commited on
Commit
9a7645b
1 Parent(s): c026d73

Create backup1.index.html

Browse files
Files changed (1) hide show
  1. backup1.index.html +130 -0
backup1.index.html ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Recursive Polygons in 3D with Continuous 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>
9
+ #canvas {
10
+ height: 500px;
11
+ width: 800px;
12
+ }
13
+ </style>
14
+ </head>
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 Components -->
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
+ meltTime: { type: 'number', default: 15000 }
34
+ },
35
+ init: function() {
36
+ let size = this.data.size;
37
+ this.el.setAttribute('geometry', {
38
+ primitive: 'sphere',
39
+ radius: size
40
+ });
41
+ this.el.setAttribute('material', { color: '#FFF' });
42
+ this.resetPosition();
43
+ this.startMeltingLoop();
44
+ },
45
+ startMeltingLoop: function() {
46
+ const resetAndStartAgain = () => {
47
+ this.resetPosition();
48
+ setTimeout(resetAndStartAgain, Math.random() * this.data.meltTime + 15000);
49
+ };
50
+ setTimeout(resetAndStartAgain, Math.random() * this.data.meltTime + 15000);
51
+ },
52
+ resetPosition: function() {
53
+ this.el.object3D.position.set(
54
+ Math.random() * 20 - 10,
55
+ 5 + Math.random() * 5,
56
+ Math.random() * 20 - 10
57
+ );
58
+ this.velocity = new THREE.Vector3(
59
+ (Math.random() - 0.5) * 0.01, // Random wind effect
60
+ -0.02, // Falling speed
61
+ (Math.random() - 0.5) * 0.01 // Random wind effect
62
+ );
63
+ },
64
+ tick: function() {
65
+ this.el.object3D.position.add(this.velocity);
66
+ if (this.el.object3D.position.y <= -3.5) {
67
+ this.el.object3D.position.y = -3.5; // Accumulate on the ground
68
+ this.velocity.set(0, 0, 0); // Stop movement when it hits the ground
69
+ }
70
+ }
71
+ });
72
+ AFRAME.registerComponent('custom-controls', {
73
+ init: function () {
74
+ this.velocityY = 0;
75
+ this.isMovingUp = false;
76
+ window.addEventListener('keydown', (e) => {
77
+ if (e.key === 'q' || e.key === 'Q') {
78
+ this.isMovingUp = true;
79
+ }
80
+ if (e.key === 'e' || e.key === 'E') {
81
+ this.velocityY = 0; // Stop upward movement
82
+ }
83
+ });
84
+ window.addEventListener('keyup', (e) => {
85
+ if (e.key === 'q' || e.key === 'Q') {
86
+ this.isMovingUp = false;
87
+ }
88
+ });
89
+ },
90
+ tick: function () {
91
+ let position = this.el.getAttribute('position');
92
+ if (this.isMovingUp) {
93
+ this.velocityY = 0.05; // Upward velocity
94
+ } else {
95
+ this.velocityY -= 0.01; // Gravity
96
+ }
97
+ position.y += this.velocityY;
98
+ if (position.y < 1.6) { // Ground level
99
+ position.y = 1.6;
100
+ this.velocityY = 0;
101
+ }
102
+ this.el.setAttribute('position', position);
103
+ }
104
+ });
105
+
106
+ function createSnowflakeCloud(x, y, z, numParticles) {
107
+ let cloud = document.createElement('a-entity');
108
+ cloud.object3D.position.set(x, y, z);
109
+ for (let i = 0; i < numParticles; i++) {
110
+ let size = Math.random() * 0.1 + 0.05; // Random size between 0.05 and 0.15
111
+ let meltTime = Math.random() * 20000 + 5000; // Random time between 5 and 25 seconds
112
+ setTimeout(() => {
113
+ let snowflakeEl = document.createElement('a-entity');
114
+ snowflakeEl.setAttribute('snowflake', {size: size, meltTime: meltTime});
115
+ cloud.appendChild(snowflakeEl);
116
+ }, i * 100);
117
+ }
118
+ document.querySelector('a-scene').appendChild(cloud);
119
+ }
120
+ // Create a grid of 9 snowflake clouds
121
+ for (let x = -10; x <= 10; x += 10) {
122
+ for (let z = -10; z <= 10; z += 10) {
123
+ createSnowflakeCloud(x, 5, z, 50); // Increase the number of particles per cloud
124
+ }
125
+ }
126
+ // Create a larger central cloud
127
+ createSnowflakeCloud(0, 8, 0, 100);
128
+ </script>
129
+ </body>
130
+ </html>