Aleksmorshen commited on
Commit
1f90e55
·
verified ·
1 Parent(s): be955ee

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +61 -0
script.js CHANGED
@@ -28,4 +28,65 @@ window.addEventListener('scroll', () => {
28
  } else {
29
  header.classList.remove('scrolled');
30
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  });
 
28
  } else {
29
  header.classList.remove('scrolled');
30
  }
31
+ });
32
+
33
+ // Three.js 3D-анимация в геро-секции (плавающие сферы)
34
+ const scene = new THREE.Scene();
35
+ const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
36
+ const renderer = new THREE.WebGLRenderer({ alpha: true });
37
+ renderer.setSize(window.innerWidth, window.innerHeight);
38
+ document.getElementById('three-canvas').appendChild(renderer.domElement);
39
+
40
+ // Свет
41
+ const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
42
+ scene.add(ambientLight);
43
+ const pointLight = new THREE.PointLight(0xff6200, 1, 100);
44
+ pointLight.position.set(10, 10, 10);
45
+ scene.add(pointLight);
46
+
47
+ // Создание сфер
48
+ const spheres = [];
49
+ const sphereGeometry = new THREE.SphereGeometry(0.5, 32, 32);
50
+ const sphereMaterial = new THREE.MeshPhongMaterial({ color: 0xff6200, emissive: 0xff6200, emissiveIntensity: 0.5 });
51
+
52
+ for (let i = 0; i < 20; i++) {
53
+ const sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
54
+ sphere.position.set(
55
+ (Math.random() - 0.5) * 20,
56
+ (Math.random() - 0.5) * 20,
57
+ (Math.random() - 0.5) * 20
58
+ );
59
+ sphere.userData = { velocity: new THREE.Vector3((Math.random() - 0.5) * 0.02, (Math.random() - 0.5) * 0.02, (Math.random() - 0.5) * 0.02) };
60
+ scene.add(sphere);
61
+ spheres.push(sphere);
62
+ }
63
+
64
+ camera.position.z = 15;
65
+
66
+ // Анимация сфер
67
+ function animate() {
68
+ requestAnimationFrame(animate);
69
+
70
+ spheres.forEach(sphere => {
71
+ sphere.position.add(sphere.userData.velocity);
72
+
73
+ // Ограничение движения
74
+ if (Math.abs(sphere.position.x) > 10) sphere.userData.velocity.x *= -1;
75
+ if (Math.abs(sphere.position.y) > 10) sphere.userData.velocity.y *= -1;
76
+ if (Math.abs(sphere.position.z) > 10) sphere.userData.velocity.z *= -1;
77
+
78
+ // Легкое вращение
79
+ sphere.rotation.x += 0.01;
80
+ sphere.rotation.y += 0.01;
81
+ });
82
+
83
+ renderer.render(scene, camera);
84
+ }
85
+ animate();
86
+
87
+ // Адаптация канваса при изменении размера окна
88
+ window.addEventListener('resize', () => {
89
+ camera.aspect = window.innerWidth / window.innerHeight;
90
+ camera.updateProjectionMatrix();
91
+ renderer.setSize(window.innerWidth, window.innerHeight);
92
  });