-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation.js
99 lines (68 loc) · 2.07 KB
/
animation.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var camera, scene, renderer;
var geometry, material, mesh;
var container, aspectRatio,
HEIGHT, WIDTH, fieldOfView,
nearPlane, farPlane,
mouseX, mouseY, windowHalfX,
windowHalfY, stats, geometry,
starMaterial, materialOptions, stars;
init();
animate();
//Animations
function init() {
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.z = 300;
scene = new THREE.Scene();
scene.background = new THREE.Color(0x000000)
geometry = new THREE.BoxGeometry(200, 200, 200);
material = new THREE.MeshBasicMaterial( { color: 0xFFFB5E, wireframe: true } );
mesh = new THREE.Mesh(geometry, material);
//mesh.position.y = 500;
scene.add(mesh);
starCreator();
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
}
function animate() {
requestAnimationFrame(animate);
scene.rotation.x += 0.00001;
scene.rotation.y += 0.00001;
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
renderer.render(scene, camera);
}
function starCreator() {
var starQuantity = 45000;
geometry = new THREE.SphereGeometry(1000, 100, 50);
materialOptions = {
size: 1.0,
opacity: 0.7
};
starMaterial = new THREE.PointsMaterial(materialOptions);
for (var i = 0; i < starQuantity; i++) {
var starVertex = new THREE.Vector3();
starVertex.x = Math.random() * 2000 - 1000;
starVertex.y = Math.random() * 2000 - 1000;
starVertex.z = Math.random() * 2000 - 1000;
geometry.vertices.push(starVertex);
}
stars = new THREE.Points(geometry, starMaterial);
scene.add(stars);
}
window.addEventListener( 'resize', resize, false );
function resize(){
location.reload()
}
/*
//Resizing the screen
window.addEventListener( 'resize', onWindowResize, false );
function onWindowResize() {
// Everything should resize nicely if it needs to!
var WIDTH = window.innerWidth,
HEIGHT = window.innerHeight;
camera.aspect = aspectRatio;
camera.updateProjectionMatrix();
renderer.setSize(WIDTH, HEIGHT);
}
*/