-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
133 lines (96 loc) · 4.11 KB
/
index.html
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<script src="js/index.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.2/TweenMax.min.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
camera.position.z = 5;
var renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setClearColor("#FFFFF0"); //setting up a background color
renderer.setSize(window.innerWidth, window.innerHeight); //setting up a background size
// Append child render DOM element to create canvas
document.body.appendChild(renderer.domElement);
// Make canvas and camera responsive and update project metrix
window.addEventListener('resize', () => {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
})
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
//creating cube
var geometry = new THREE.BoxGeometry(2, 2, 2); //the higher you go the smppther rounds
var material = new THREE.MeshNormalMaterial();
var mesh = new THREE.Mesh(geometry, material);
mesh.position.set(0, 0, -2)
scene.add(mesh);
// meshX = -100;
// for (var k = 0; k < 14; k++) {
// var mesh = new THREE.Mesh(geometry, material);
// mesh.position.x = ((Math.random() - 0.5) * 10);
// mesh.position.y = ((Math.random() - 0.5) * 10);
// mesh.position.z = ((Math.random() - 0.5) * 10);
// scene.add(mesh);
// meshX += 1;
// }
var light = new THREE.PointLight(0xFFFF00, 1, 500);
light.position.set(0, 0, 25);
scene.add(light);
for (var i = 0, l = geometry.vertices.length; i < l; i++) {
geometry.vertices[i].x += -1 + (Math.random() - 0.5) * 2;
geometry.vertices[i].y += -1 + (Math.random() - 0.5) * 2;
}
//render background specifics for camera and scene, adjust animation
var render = function () {
requestAnimationFrame(render);
mesh.rotation.x += 0.02;
mesh.rotation.y += 0.01;
mesh.rotation.y -= 0.02;
renderer.render(scene, camera);
}
function onMouseMove(event) {
event.preventDefault();
// calculate mouse position in normalized device coordinates
// (-1 to +1) for both components
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
var intersects = raycaster.intersectObjects(scene.children, true);
for (var i = 0; i < intersects.length; i++) {
tl = new TimelineMax();
tl.to(intersects[i].object.position, .3, {
y: (Math.random() - 0.5) * 8
})
tl.to(intersects[i].object.position, .3, {
x: (Math.random() - 0.5) * 8
})
tl.to(intersects[i].object.position, .3, {
y: (Math.random() - 0.5) * 8
})
tl.to(intersects[i].object.rotation, .3, {
x: (Math.random() - 0.5) * 2
})
tl.to(intersects[i].object.scale, .2, {
x: (Math.random() - 0.5) * 2
})
tl.to(intersects[i].object.scale, .2, {
y: (Math.random() - 0.5) * 2
})
}
}
render();
window.addEventListener('click', onMouseMove);
</script>
</body>
</html>