-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
78 lines (63 loc) · 2.19 KB
/
app.js
File metadata and controls
78 lines (63 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//------------------Scene & Camera & Controls------------------
let scene = new THREE.Scene();
let camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.z = 5;
document.addEventListener('mousemove', onDocumentMouseMove, false);
//------------------Drawables------------------
let ring = new THREE.Mesh(new THREE.RingBufferGeometry(1, 20, 100), new THREE.MeshBasicMaterial( {color: 0x000000}));
scene.add(ring);
starGeo = new THREE.Geometry();
for(let i=0;i<100000;i++) {
star = new THREE.Vector3(
Math.random() * 600 - 300,
Math.random() * 600 - 300,
Math.random() * 600 - 300
);
star.velocity = 0;
star.acceleration = 1;
starGeo.vertices.push(star);
}
let starMaterial = new THREE.PointsMaterial({
color: 0xffffff,
size: 0.7
});
stars = new THREE.Points(starGeo,starMaterial);
scene.add(stars);
window.addEventListener("resize", onWindowResize, false);
//------------------Renderer------------------
let renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.BasicShadowMap;
let mousePos = { x: 0, y: 0 };
let counter = true;
//------------------Functions------------------
function onDocumentMouseMove(mouse){
console.log(mouse.x)
mx = (event.clientX / window.innerWidth) * 14 - 7;
my = - (event.clientY / window.innerHeight) * 8 + 4;
mousePos = {x:mx, y:my};
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
starGeo.vertices.forEach(p => {
p.velocity = p.acceleration
p.y -= p.velocity;
p.z = -40;
ring.position.y = mousePos.y;
ring.position.x = mousePos.x;
if (p.y < -200) {
p.y = 100;
p.velocity = 0;
}
});
starGeo.verticesNeedUpdate = true;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();