-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
80 lines (64 loc) · 2.09 KB
/
script.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
/* global THREE:true, $:true */
function onStart() {
'use strict';
var
onResizeEnd, theGeometry, theMaterial, theLight, theLight2, elem,
cubes = [],
theColor = 0x60A1E1,
transition = 0.002,
body = $('body'), h = body.height(), w = body.width(),
theContainer = $("#animation"),
theRenderer = new THREE.WebGLRenderer({alpha: true}),
theScene = new THREE.Scene(),
theCamera = new THREE.PerspectiveCamera(75, w / h, 0.1, 1000);
theRenderer.setSize(w, h);
theCamera.position.set(0, 0, 10);
theContainer.replaceWith(theRenderer.domElement);
theMaterial = new THREE.MeshLambertMaterial({
color: theColor
});
$(window).resize(function () {
clearTimeout(onResizeEnd);
onResizeEnd = setTimeout(function () {
var
h = body.height(),
w = body.width();
theRenderer.setSize(w, h);
theCamera.aspect = w / h;
theCamera.updateProjectionMatrix();
}, 400);
});
function buildScene(cubeNumber, cubeSize) {
cubes = [];
theGeometry = new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize);
for (var i = 0; i < cubeNumber; i += 1) {
for (var k = 0; k < cubeNumber; k += 1) {
elem = new THREE.Mesh(theGeometry, theMaterial);
cubes.push(elem);
elem.position.set(-(cubeNumber * cubeSize / 2) + (cubeSize * k), -(cubeNumber * cubeSize / 2) + (cubeSize * i), 0);
theScene.add(elem);
}
}
}
buildScene(Math.round(w / 16), w / 600);
theLight = new THREE.DirectionalLight(0xD2D2D2, 1);
theLight.position.set(20, 20, 20);
theScene.add(theLight);
theLight2 = new THREE.DirectionalLight(0x193549 /*3B5CA9*/, 1.2);
theLight2.position.set(-20, -20, 20);
theScene.add(theLight2);
requestAnimationFrame(animate);
setInterval(function () {
transition = -transition;
}, 4000);
function animate() {
theRenderer.render(theScene, theCamera);
$(cubes).map(function (index, cube) {
cube.rotation.y += 0.004;
cube.rotation.x += 0.004;
cube.position.x += transition;
cube.position.x += transition;
});
requestAnimationFrame(animate);
}
}