-
Notifications
You must be signed in to change notification settings - Fork 52
/
index-brain.html
executable file
·79 lines (75 loc) · 3.37 KB
/
index-brain.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
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Exploding 3D Objects | Brain | Codrops</title>
<meta name="description" content="An exploding objects effect made with three.js." />
<meta name="keywords" content="webgl, 3d, objects, exploding, shatter, fragment, animation, template, javascript" />
<meta name="author" content="Codrops" />
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="https://use.typekit.net/tsb3xby.css">
<link rel="stylesheet" type="text/css" href="css/base.css" />
<script>document.documentElement.className="js";var supportsCssVars=function(){var e,t=document.createElement("style");return t.innerHTML="root: { --tmp-var: bold; }",document.head.appendChild(t),e=!!(window.CSS&&window.CSS.supports&&window.CSS.supports("font-weight","var(--tmp-var)")),t.parentNode.removeChild(t),e};supportsCssVars()||alert("Please view this demo in a modern browser that supports CSS Variables.");</script>
</head>
<body class="demo-brain loading">
<main><div id="container"></div>
<div class="frame">
<div class="frame__deco">Move your mouse around.</div>
<div class="frame__title-wrap">
<h1 class="frame__title">Exploding 3D Objects</h1>
<div class="frame__links">
<a href="https://tympanus.net/Development/SVGImageHover/">Previous Demo</a>
<a href="https://tympanus.net/codrops/?p=39110">Article</a>
<a href="https://github.com/codrops/ExplodingObjects/">GitHub</a>
</div>
</div>
<p class="frame__credits">Inspired by <a href="https://dribbble.com/shots/6019111-Kubrick-Life-Website-3D-Motion">Kubrick Life Website: 3D Motion</a></p>
<div class="frame__demos">
<a href="index.html" class="frame__demo">Demo 1</a>
<a href="index2.html" class="frame__demo">Demo 2</a>
<a href="index3.html" class="frame__demo">Demo 3</a>
<a href="index4.html" class="frame__demo">Demo 4</a><br/>
<a href="index-icosahedron.html" class="frame__demo">Icosahedron</a>
<a href="index-heart.html" class="frame__demo">Heart</a>
<a href="index-egg.html" class="frame__demo">Egg</a>
<a href="index-brain.html" class="frame__demo frame__demo--current">Brain</a>
</div>
</div><!-- /frame -->
</main>
<script src="js/brain.js"></script>
<script>
let animation = new explosion.default(
'container', // id of DOM el
{
surface: 'ffe2e2',
inside: 'f56969',
background: '151616',
onLoad: () => {
document.body.classList.remove('loading');
}
}
);
let targetMouseX = 0, mouseX = 0, ta = 0;
const sign = function(n) { return n === 0 ? 1 : n/Math.abs(n); };
document.addEventListener('mousemove',(e) => {
targetMouseX = 2*(e.clientX - animation.width/2)/animation.width;
});
document.addEventListener('touchmove',(e) => {
targetMouseX = ( e.touches[0].clientX / animation.width ) * 2 - 1;
});
animation.camera.position.z = 500;
function draw(){
if(animation){
mouseX += (targetMouseX - mouseX)*0.05;
ta = Math.abs(mouseX);
if(ta<0.15) {ta1 =0;} else {ta1 = ta - 0.15;}
animation.settings.progress = ta1*ta1*ta1;
animation.scene.rotation.y = 0.2 *-ta*(2 - ta)*Math.PI * sign(mouseX);
}
window.requestAnimationFrame(draw);
}
draw()
</script>
</body>
</html>