-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
456 lines (328 loc) · 17.3 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
<!DOCTYPE html>
<html lang="en">
<head>
<title>Github projects</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link type="text/css" rel="stylesheet" href="main.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/devicons/[email protected]/devicon.min.css">
</head>
<body>
<div id="container"></div>
<div id="menu">
<button id="stack">STACK</button>
<button id="sphere">SPHERE</button>
<button id="helix">HELIX</button>
<button id="grid">GRID</button>
</div>
<!-- SVG for external link -->
<!-- <svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="24" height="24" viewBox="0 0 24 24"
style=" fill:#000000;">
<path
d="M 19.980469 2.9902344 A 1.0001 1.0001 0 0 0 19.869141 3 L 15 3 A 1.0001 1.0001 0 1 0 15 5 L 17.585938 5 L 8.2929688 14.292969 A 1.0001 1.0001 0 1 0 9.7070312 15.707031 L 19 6.4140625 L 19 9 A 1.0001 1.0001 0 1 0 21 9 L 21 4.1269531 A 1.0001 1.0001 0 0 0 19.980469 2.9902344 z M 5 3 C 3.9069372 3 3 3.9069372 3 5 L 3 19 C 3 20.093063 3.9069372 21 5 21 L 19 21 C 20.093063 21 21 20.093063 21 19 L 21 13 A 1.0001 1.0001 0 1 0 19 13 L 19 19 L 5 19 L 5 5 L 11 5 A 1.0001 1.0001 0 1 0 11 3 L 5 3 z">
</path>
</svg> -->
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@latest/build/three.module.js"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import TWEEN from 'https://unpkg.com/three@latest/examples/jsm/libs/tween.module.js';
import { TrackballControls } from 'https://unpkg.com/three@latest/examples/jsm/controls/TrackballControls.js';
import { CSS3DRenderer, CSS3DObject } from 'https://unpkg.com/three@latest/examples/jsm/renderers/CSS3DRenderer.js';
// var repo_name = document.querySelector('.repo_name');
// var repo_nameContainer = document.querySelector('.repo_card');
// var devicon = '<i class="devicon-${icon}-plain colored"></i> ${icon}'
const devicons = {
Git: '<i class="devicon-git-plain" style="color: #555"></i>',
Github: '<i class="devicon-github-plain" style="color: #1688f0"></i>',
Chrome: '<i class="devicon-chrome-plain" style="color: #1688f0"></i>',
Assembly: '<i class="devicon-labview-plain colored"></i> Assembly',
'C#': '<i class="devicon-csharp-plain colored"></i> C#',
'C++': '<i class="devicon-cplusplus-plain colored"></i> C++',
C: '<i class="devicon-c-plain colored"></i> C',
Clojure: '<i class="devicon-clojure-plain colored"></i> C',
CoffeeScript:
'<i class="devicon-coffeescript-plain colored"></i> CoffeeScript',
Crystal: '<i class="devicon-crystal-plain colored"></i> Crystal',
CSS: '<i class="devicon-css3-plain colored"></i> CSS',
Dart: '<i class="devicon-dart-plain colored"></i> Dart',
Dockerfile: '<i class="devicon-docker-plain colored"></i> Docker',
Elixir: '<i class="devicon-elixir-plain colored"></i> Elixir',
Elm: '<i class="devicon-elm-plain colored"></i> Elm',
Erlang: '<i class="devicon-erlang-plain colored"></i> Erlang',
'F#': '<i class="devicon-fsharp-plain colored"></i> F#',
Go: '<i class="devicon-go-plain colored"></i> Go',
Groovy: '<i class="devicon-groovy-plain colored"></i> Groovy',
HTML: '<i class="devicon-html5-plain colored"></i> HTML',
Haskell: '<i class="devicon-haskell-plain colored"></i> Haskell',
Java: '<i class="devicon-java-plain colored" style="color: #ffca2c"></i> Java',
JavaScript: '<i class="devicon-javascript-plain colored"></i> JavaScript',
Julia: '<i class="devicon-julia-plain colored"></i> Julia',
'Jupyter Notebook': '<i class="devicon-jupyter-plain colored"></i> Jupyter',
Kotlin: '<i class="devicon-kotlin-plain colored" style="color: #796bdc"></i> Kotlin',
Latex: '<i class="devicon-latex-plain colored"></i> Latex',
Lua: '<i class="devicon-lua-plain-wordmark colored" style="color: #0000d0"></i> Lua',
Matlab: '<i class="devicon-matlab-plain colored"></i> Matlab',
Nim: '<i class="devicon-nixos-plain colored" style="color: #FFC200"></i> Nim',
Nix: '<i class="devicon-nixos-plain colored"></i> Nix',
ObjectiveC: '<i class="devicon-objectivec-plain colored"></i> ObjectiveC',
OCaml: '<i class="devicon-ocaml-plain colored"></i> OCaml',
Perl: '<i class="devicon-perl-plain colored"></i> Perl',
PHP: '<i class="devicon-php-plain colored"></i> PHP',
PLSQL: '<i class="devicon-sqlite-plain colored"></i> PLSQL',
Processing:
'<i class="devicon-processing-plain colored" style="color: #0096D8"></i> Processing',
Python: '<i class="devicon-python-plain colored" style="color: #3472a6"></i> Python',
R: '<i class="devicon-r-plain colored"></i> R',
Ruby: '<i class="devicon-ruby-plain colored"></i> Ruby',
Rust: '<i class="devicon-rust-plain colored" style="color: #DEA584"></i> Rust',
Sass: '<i class="devicon-sass-original colored"></i> Sass',
Scala: '<i class="devicon-scala-plain colored"></i> Scala',
Shell: '<i class="devicon-bash-plain colored" style="color: #89E051"></i> Shell',
Solidity: '<i class="devicon-solidity-plain colored"></i> Solidity',
Stylus: '<i class="devicon-stylus-plain colored"></i> Stylus',
Svelte: '<i class="devicon-svelte-plain colored"></i> Svelte',
Swift: '<i class="devicon-swift-plain colored"></i> Swift',
Terraform: '<i class="devicon-terraform-plain colored"></i> Terraform',
TypeScript: '<i class="devicon-typescript-plain colored"></i> TypeScript',
'Vim Script': '<i class="devicon-vim-plain colored"></i> Vim Script',
Vue: '<i class="devicon-vuejs-plain colored"></i> Vue',
};
const resizeToFit = (repo_name, repo_nameContainer) => {
let fontSize = window.getComputedStyle(repo_name).fontSize;
repo_name.style.fontSize = (parseFloat(fontSize) - 1) + 'px';
if (repo_name.clientHeight >= repo_nameContainer.clientHeight) {
resizeToFit(repo_name, repo_nameContainer);
}
}
var stack = new Array();
//get url of the github page and split it to get username
var url = window.location.href;
var username = url.split(".")[0].split("//")[1];
// var username = "AMIT0617";
await fetch('/repos.json')
.then(async response => {
if (response.status !== 404) {
let data = await response.json();
return data;
}
else {
response = await fetch(`https://api.github.com/users/${username}/repos?&sort=pushed&per_page=100`);
let data = await response.json();
// console.log(data);
return data;
}
})
.then(data => {
for (let index = 0; index < data.length; index++) {
let repo = data[index];
stack.push(repo);
}
stack.sort((a) => a.stargazers_count);
console.log(stack);
})
.catch(err => console.log(err));
console.log(stack);
let camera, scene, renderer;
let controls;
const objects = [];
const targets = { stack: [], sphere: [], helix: [], grid: [] };
let mouseX = 0, mouseY = 0;
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.z = 500;
// make background scene consisting matrix of lines in three.js
scene = new THREE.Scene();
// stack
for (let i = 0; i < stack.length; i++) {
const repo_card = document.createElement('div');
repo_card.className = 'repo_card';
repo_card.style.backgroundColor = 'rgba(255,255,255,' + (Math.random() * 0.5 + 0.25) + ')';
const repo_name = document.createElement('a');
repo_name.className = 'repo_name';
repo_name.textContent = stack[i].name;
// resizeToFit(repo_name, repo_card);
repo_name.href = stack[i].html_url;
repo_card.appendChild(repo_name);
const description = document.createElement('div');
description.className = 'description';
description.innerText = stack[i].description == null ? null : stack[i].description.length > 50 ? stack[i].description.substr(0, 50) + '...' : stack[i].description;
repo_card.appendChild(description);
const centerdiv = document.createElement('div');
centerdiv.className = 'centerdiv';
if (stack[i].language) {
// const language = document.createElement('p')
// language.className = 'language'
// language.innerHTML = devicons[stack[i].language];
centerdiv.innerHTML += devicons[stack[i].language];
centerdiv.classList.add('language');
}
if (stack[i].stargazers_count) {
// const stars = document.createElement('p');
// stars.className = 'stars';
// stars.innerText += '⭐' + stack[i].stargazers_count;
centerdiv.innerHTML += '⭐' + stack[i].stargazers_count;
}
if (stack[i].forks_count) {
// const forks = document.createElement('p')
// forks.innerHTML += devicons["Git"] + stack[i].forks_count;
centerdiv.innerHTML += devicons["Git"] + stack[i].forks_count;
// centerdiv.appendChild(forks);
}
if (stack[i].has_pages) {
const homepage = document.createElement('a');
homepage.href = stack[i].homepage;
homepage.innerHTML = devicons["Chrome"] + stack[i].name;
// centerdiv.innerHTML += devicons["Chrome"];
// centerdiv.classList.add('homepage')
homepage.className = 'homepage';
centerdiv.appendChild(homepage);
}
repo_card.appendChild(centerdiv);
// Default landing of the cards
const objectCSS = new CSS3DObject(repo_card);
objectCSS.position.x = Math.random() * 400 - 200;
objectCSS.position.y = Math.random() * 400 - 200;
objectCSS.position.z = Math.random() * 400 - 200;
scene.add(objectCSS);
const time = Date.now() * 0.001;
objects.push(objectCSS);
objectCSS.rotation.y = time * 0.5
// stack - customise below to change the positions
const object = new THREE.Object3D();
// object.position.x = (i * 140) - 130;
// object.position.y = ([i + 3] * 180) + 990;
targets.stack.push(object);
}
// sphere
const vector = new THREE.Vector3();
for (let i = 0, l = objects.length; i < l; i++) {
// 2 multiplied with i here decides a spiral height
// less than that will need more elements to complete circle
const phi = Math.acos(-1 + (2 * i) / l);
const theta = Math.sqrt(l * Math.PI) * phi;
const object = new THREE.Object3D();
object.position.setFromSphericalCoords(500, phi, theta); //500 decides radius for sphere
vector.copy(object.position).multiplyScalar(2);
object.lookAt(vector);
targets.sphere.push(object);
}
// helix
for (let i = 0, l = objects.length; i < l; i++) {
const theta = i * 0.25 + Math.PI; // for making cards overlap each other adjust 0.3 to lower
const y = - (i * 20) + 900; // height of spiral
const object = new THREE.Object3D();
object.position.setFromCylindricalCoords(800, theta, y); // radius
vector.x = object.position.x * 2;
vector.y = object.position.y;
vector.z = object.position.z * 2;
object.lookAt(vector);
targets.helix.push(object);
}
// grid
for (let i = 0; i < objects.length; i++) {
const object = new THREE.Object3D();
// constant after minus for shifting on axis (500)
// multiplier (200) for deciding gap between cards
// modulo for no. of cards(5) in a row
object.position.x = ((i % 3) * 500) - 500;
object.position.y = (- (Math.floor(i / 5) % 3) * 200) + 300;
object.position.z = (Math.floor(i / 25)) * 1000 - 2000;
targets.grid.push(object);
}
//
renderer = new CSS3DRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('container').appendChild(renderer.domElement);
//
controls = new TrackballControls(camera, renderer.domElement);
controls.minDistance = 10;
controls.maxDistance = 4000;
controls.addEventListener('change', render);
const buttonTable = document.getElementById('stack');
buttonTable.addEventListener('click', function () {
transform(targets.stack, 2000);
play();
});
const buttonSphere = document.getElementById('sphere');
buttonSphere.addEventListener('click', function () {
transform(targets.sphere, 2000);
play();
});
const buttonHelix = document.getElementById('helix');
buttonHelix.addEventListener('click', function () {
transform(targets.helix, 2000);
play();
});
const buttonGrid = document.getElementById('grid');
buttonGrid.addEventListener('click', function () {
transform(targets.grid, 2000);
play();
});
transform(targets.stack, 2000);
//play audio on click of button
const audio = new Audio('swoosh-6428.mp3')
// const audio = new Audio('mystical-wind-chimes-transition-fx-6327.mp3')
function play() {
setTimeout(() => audio.play(), 800);
};
window.addEventListener('resize', onWindowResize);
}
function transform(targets, duration) {
TWEEN.removeAll();
for (let i = 0; i < objects.length; i++) {
const object = objects[i];
const target = targets[i];
new TWEEN.Tween(object.position)
.to({ x: target.position.x, y: target.position.y, z: target.position.z }, Math.random() * duration + duration)
.easing(TWEEN.Easing.Exponential.InOut)
.start();
new TWEEN.Tween(object.rotation)
.to({ x: target.rotation.x, y: target.rotation.y, z: target.rotation.z }, Math.random() * duration + duration)
.easing(TWEEN.Easing.Exponential.InOut)
.start();
}
new TWEEN.Tween(this)
.to({}, duration * 3)
.onUpdate(render)
.start();
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
requestAnimationFrame(animate);
const vector = new THREE.Vector3();
TWEEN.update();
controls.update();
render();
}
function render() {
// adjust camera position with smoothness on mouse move
camera.position.x += (mouseX - camera.position.x) * 0.05;
camera.position.y += (- mouseY + 200 - camera.position.y) * 0.05;
camera.lookAt(scene.position);
const time = Date.now() * 0.0005;
for (let i = 0; i < scene.children.length; i++) {
const object = scene.children[i];
if (object.isLine) {
object.rotation.y = time * (i % 2 ? 1 : - 1);
}
}
renderer.render(scene, camera);
}
</script>
</body>
</html>