awacke1 commited on
Commit
d92817a
·
1 Parent(s): e2a660a

Update index.html

Browse files
Files changed (1) hide show
  1. 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="lettersContainer"></a-entity>
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.generateLetter(key);
25
  }
26
  });
27
  },
28
- generateLetter: function (key) {
29
- const lettersContainer = document.querySelector('#lettersContainer');
30
- const letter = document.createElement('a-entity');
31
- letter.setAttribute('text', { value: key.toUpperCase(), align: 'center', font: 'https://cdn.aframe.io/fonts/Exo2SemiBold.fnt', width: 2 });
32
- letter.setAttribute('position', '0 1 -5');
33
- letter.setAttribute('rotation', '0 0 0');
34
- letter.setAttribute('scale', '1 1 1');
35
- letter.setAttribute('letter', '');
36
- lettersContainer.appendChild(letter);
 
 
 
 
 
 
 
37
  }
38
  });
39
 
40
- AFRAME.registerComponent('letter', {
41
- init: function () {
42
- this.el.setAttribute('animation', { property: 'rotation', to: '0 360 0', dur: 2000, easing: 'linear', loop: true });
43
- this.el.setAttribute('animation__position', { property: 'position', to: '0 1 20', dur: 2000, easing: 'linear', loop: true });
 
 
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>