-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
329 lines (289 loc) · 13.5 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Meta -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Pinnacle, Coding, software, firm, consulting, web, mobile, backend, Mitchell, Sayer, David, Hacker">
<meta name="author" content="Pinnacle Coding">
<!-- Title -->
<title>Pinnacle Coding</title>
<!-- Favicon -->
<link href="/static/assets/Buddhabrot.png" rel="icon" type="image/png">
<!-- Fonts -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" type='text/css'>
<!-- CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/css/materialize.min.css" rel='stylesheet' type='text/css'>
<style>
body {
margin: 0;
}
canvas {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
}
</style>
</head>
<body>
<div class="fixed-action-btn horizontal click-to-toggle" style="bottom: 45px; right: 24px;">
<a class="btn-floating btn-large grey darken-3 waves-effect waves-light">
<i class="material-icons">swap_horiz</i>
</a>
<ul>
<li><a class="btn-floating grey darken-2 waves-effect waves-light" id="fab-previous"><i class="material-icons">skip_previous</i></a></li>
<li><a class="btn-floating grey darken-2 waves-effect waves-light" id="fab-next"><i class="material-icons">skip_next</i></a></li>
</ul>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/js/materialize.min.js"></script>
<script src="/static/js/three.min.js"></script>
<script src="/static/js/Tween.js"></script>
<script>
window.onload = function () {
var scene, camera, renderer;
var controls;
var nodes;
var node_connections;
var node_path;
var camera_positions;
var stage, iteration;
var node_text;
init();
animate();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000);
document.body.appendChild(renderer.domElement);
var ambient = new THREE.AmbientLight(0x333333);
scene.add(ambient);
var light = new THREE.DirectionalLight(0xffffff);
light.position.set(-200, 200, 200);
light.target.position.set(0, 0, 0);
scene.add(light);
var node_layers = [1, 3, 3, 5, 6];
var xz_positions = {
1: [[0, 0]],
3: [[-25, 0], [25, 0], [0, -25]],
5: [[-50, 0], [50, 0], [0, -25], [-50, -50], [50, -50]],
6: [[-50, 0], [0, 0], [50, 0], [-50, -50], [0, -50], [50, -50]]
};
var layer_colours = [0x2196f3, 0x1de9b6, 0xf44336, 0x673ab7, 0xff9800];
nodes = [];
camera_positions = [];
stage = 0;
iteration = 0;
var y_max = 100;
var y_min = -100;
var y_separation_distance = (y_max - y_min) / (node_layers.length - 1);
// Set up nodes/spheres
for (var i = 0; i < node_layers.length; i++) {
var num_nodes = node_layers[i];
var xz_for_num_nodes = xz_positions[num_nodes];
var y = y_max - y_separation_distance * i;
var node_layer = [];
for (var j = 0; j < num_nodes; j++) {
var geometry = new THREE.SphereGeometry(5, 32, 32);
var material = new THREE.MeshPhongMaterial({
color: layer_colours[i],
specular: 0x353535,
//specular: layer_colours[i]
shininess: 10
});
var sphere = new THREE.Mesh(geometry, material);
scene.add(sphere);
sphere.position.set(xz_for_num_nodes[j][0], y, xz_for_num_nodes[j][1]);
node_layer.push(sphere);
}
nodes.push(node_layer);
}
// Set up connections between nodes/lines
node_connections = [];
for (var i = 0; i < node_layers.length - 1; i++) {
var layer_connections = [];
for (var j = 0; j < node_layers[i]; j++) {
var current_node = nodes[i][j];
var neuron_connections = [];
for (var k = 0; k < node_layers[i + 1]; k++) {
var next_node = nodes[i + 1][k];
var material = new THREE.LineBasicMaterial({
color: 0xffffff
});
var geometry = new THREE.Geometry();
geometry.vertices.push(current_node.position);
geometry.vertices.push(next_node.position);
var line = new THREE.Line(geometry, material);
scene.add(line);
neuron_connections.push(line);
}
layer_connections.push(neuron_connections);
}
node_connections.push(layer_connections);
}
// Set up path visting a node in each layer
node_path = [];
for (var i = 0; i < nodes.length; i++) {
node_path.push(Math.floor(Math.random() * nodes[i].length));
}
for (var i = 0; i < node_path.length; i++) {
var node_layer = nodes[i];
var ax = 0;
var ay = 0;
var az = 0;
for (var j = 0; j < node_layer.length; j++) {
var sphere = node_layer[j];
ax += sphere.position.x;
ay += sphere.position.y;
az += sphere.position.z;
}
ax /= node_layer.length;
ay /= node_layer.length;
az /= node_layer.length;
var average_position = new THREE.Vector3(ax, ay, az);
for (var j = 0; j < node_layer.length; j++) {
var sphere = node_layer[j];
if (j === node_path[i]) {
sphere.material.color.setHex(0x00ff00);
if (sphere.position.clone().sub(average_position).length() < 0.001) {
average_position = new THREE.Vector3(1000, average_position.y, 10000);
}
var direction = sphere.position.clone().sub(average_position).normalize().multiplyScalar(30);
var position = sphere.position.clone().add(direction);
camera_positions.push(position);
} else {
//sphere.material.color.setHex(0xffffff);
}
}
}
camera_positions.push(new THREE.Vector3(0, 0, 150));
for (var i = 0; i < node_path.length - 1; i++) {
var connections_to_next_layer = node_connections[i];
for (var j = 0; j < connections_to_next_layer.length; j++) {
for (var k = 0; k < connections_to_next_layer[j].length; k++) {
var line = connections_to_next_layer[j][k];
if (j === node_path[i] && k === node_path[i + 1]) {
line.material.color.setHex(0x00ff00);
} else {
line.material.color.setHex(0xffffff);
}
}
}
}
// Set up 'Pinnacle Coding' at end
node_text = [[], [], [], [], [], []];
var loader = new THREE.FontLoader();
loader.load("/static/fonts/Raleway_Regular.json", function (font) {
var geometry = new THREE.TextGeometry("PINNACLE CODING", {
font: font,
size: 20,
height: 3
});
var material = new THREE.MeshPhongMaterial({
color: 0xffffff,
specular: 0x353535,
shininess: 10,
opacity: 0,
transparent: true
});
var textMesh = new THREE.Mesh(geometry, material);
geometry.center();
textMesh.position.set(0, 0, 50);
textMesh.lookAt(camera.position);
scene.add(textMesh);
node_text[5].push(textMesh);
});
// Set up initial camera position
var pos1 = camera_positions[stage];
camera.position.set(pos1.x, pos1.y, pos1.z);
// Window resize listener
window.addEventListener('resize', function () {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}, false);
}
function animate() {
TWEEN.update(); // Update camera position first
var cpos = camera.position.clone();
camera.lookAt(new THREE.Vector3(0, cpos.y, 0));
for (var i = 0; i < node_text.length; i++) {
var text_objects = node_text[i];
if (stage === i) {
for (var j = 0; j < text_objects.length; j++) {
var obj = text_objects[j];
obj.lookAt(camera.position);
obj.visible = true;
obj.material.opacity += 0.005;
if (obj.material.opacity > 1) {
obj.material.opacity = 1;
}
}
} else {
for (var j = 0; j < text_objects.length; j++) {
var obj = text_objects[j];
obj.material.opacity -= 0.005;
if (obj.material.opacity < 0) {
obj.material.opacity = 0;
obj.visible = false;
}
}
}
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
iteration++;
}
function nextStage() {
if (stage < camera_positions.length - 1) {
stage++;
onChangeStage();
}
}
function previousStage() {
if (stage > 0) {
stage--;
onChangeStage();
}
}
function onChangeStage() {
var position = camera.position.clone();
var target = camera_positions[stage];
var tween = new TWEEN.Tween(position).to(target, 1500);
tween.onUpdate(function () {
camera.position.set(position.x, position.y, position.z);
});
tween.easing(TWEEN.Easing.Sinusoidal.InOut);
tween.start();
if (stage === 5) {
var mainTextPosition = node_text[5][0].position.clone();
var mainTextTarget = new THREE.Vector3(0, 60, 20);
var mainTextTween = new TWEEN.Tween(mainTextPosition).to(mainTextTarget, 5000);
mainTextTween.onUpdate(function () {
node_text[5][0].position.set(mainTextPosition.x, mainTextPosition.y, mainTextPosition.z);
});
mainTextTween.easing(TWEEN.Easing.Exponential.Out);
mainTextTween.delay(1000);
mainTextTween.start();
}
}
window.onkeydown = function (e) {
e = e || window.event;
if (e.keyCode === 40 || e.keyCode === 39) {
nextStage();
} else if (e.keyCode === 38 || e.keyCode === 37) {
previousStage();
}
}
document.getElementById("fab-previous").addEventListener("click", previousStage);
document.getElementById("fab-next").addEventListener("click", nextStage);
}
</script>
</body>
</html>