test / index.html
SaulLu's picture
add website
db66552
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>learning@home</title>
<meta name="description" content="A library to train large neural networks across the internet. Imagine training GPT-3 on thousands of nodes from universities, companies, and volunteers.">
<link rel="mask-icon" href="logo_small.png">
<link rel="alternate icon" class="js-site-favicon" type="image/png" href="logo.png">
<link rel="icon" class="js-site-favicon" type="image/png" href="logo.png">
<meta property="og:url" content="https://learning-at-home.github.io">
<meta property="og:site_name" content="learning@home">
<meta property="og:title" content="Train vast neural networks together">
<meta property="og:description" content="A library to train large neural networks across the internet. Imagine training one huge transformer on thousands of computers from universities, companies, and volunteers.">
<meta property="og:image" content="https://learning-at-home.github.io/logo_small.png">
<meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="96">
<meta property="og:image:height" content="96">
<meta property="twitter:site" content="https://github.com/learning-at-home/hivemind">
<meta property="twitter:creator" content="learning@home contributors">
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:title" content="learning@home">
<meta property="twitter:description" content="Hivemind is a library to train large neural networks across the internet. Imagine training one huge transformer on thousands of computers from universities, companies, and volunteers.">
<meta property="twitter:image:src" content="https://learning-at-home.github.io/logo_horizontal.png">
<link rel="stylesheet" href="https://unpkg.com/flickity@2/dist/flickity.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/flickity@2/dist/flickity.pkgd.min.js"></script>
</head>
<style>
:root {
--border-color: black;
--window-color: white;
--background-move-on-cursor: false;
--background-color: white;
--background-cursor-width: 400;
--background-cursor-height: 200;
--background-show-if-wider-than: 500;
--background-speed: 0.001;
--energy-decay: 0.3;
}
body {
width: 100%;
margin: 0 auto;
background-color: var(--background-color);
}
#container {
position: relative;
width: 100%;
margin: 0 auto;
}
#container canvas, #overlay {
width: 100%;
margin: 0 auto;
position: absolute;
}
canvas {
background-color: var(--background-color);
width: 0px; /* will be changed on init */
overflow: hidden;
}
#main_window {
width: 80%;
min-width: 350px;
margin: 0 auto;
text-align: center;
}
.faded {
margin: 0 auto;
background: var(--window-color);
box-shadow: 0 0 5px 5px var(--window-color);
font-family: cursive;
font-family: "Gill Sans", sans-serif;
display: inline-block
}
.title {
font-size: 48px;
box-shadow: 0 0 5px 5px var(--window-color);
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,
sans-serif,Apple Color Emoji,Segoe UI Emoji;
}
.text {
font-size: 16px;
box-shadow: 0 0 5px 5px var(--window-color);
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,
sans-serif,Apple Color Emoji,Segoe UI Emoji;
}
.scrollbar {
overflow-y: scroll;
}
.arxiv_button {
position: relative;
display: inline-block;
width: 80px;
height: 28px;
background-image: linear-gradient(180deg, #fafbfc, #eff3f6 90%);
color: #24292e;
border: 1px solid rgba(27,31,35,.2);
text-align: center;
cursor: pointer;
border-radius: 4px;
padding-right: 0px;
padding-top: 2.5px;
font-size: 12px;
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif;
font-weight: 600;
}
.arxiv_button:before {
content: "";
vertical-align:middle;
display: inline-block;
width: 24px;
height: 24px;
border: none;
margin-left: -16px;
margin-right: 4px;
margin-top: -2px;
background: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" class="ionicon s-ion-icon" viewBox="0 0 512 512"><path d="M428 224H288a48 48 0 01-48-48V36a4 4 0 00-4-4h-92a64 64 0 00-64 64v320a64 64 0 0064 64h224a64 64 0 0064-64V228a4 4 0 00-4-4z"></path><path d="M419.22 188.59L275.41 44.78a2 2 0 00-3.41 1.41V176a16 16 0 0016 16h129.81a2 2 0 001.41-3.41z"></path></svg>') right center no-repeat;
background-size: 18px 16px;
}
.arxiv_button:hover {
background-color:#e6ebf1;
background-position:-0.5em;
border-color: #9fa4a9;
border-color:rgba(27,31,35,.35);
background-image:linear-gradient(180deg, #f0f3f6, #e6ebf1 90%)
}
a:link {
color: #00194a;
text-decoration: none;
}
a:visited {
color: #3f004a;
text-decoration: none;
}
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 240px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -60px;
opacity: 0;
transition: opacity 0.3s;
}
.tooltip .tooltiptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
</style>
<body>
<div id="container">
<canvas></canvas>
<div id="overlay">
<div id="main_window">
<div id="header">
<img src="logo.png" id="bug-logo"
style="width: 40%; max-height: 320px; max-width: 320px; z-index:1000; position: relative;">
<br>
<h1 class="faded title" style="margin-top:-3%;">
<p style="margin-top: 0px; margin-bottom:0px;">
<sup style="font-size: 18px">learning@home</sup>
<span id="title_text">hivemind</span>
<sup style="font-size: 18px">v0.10&nbsp;beta&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</sup>
</p>
<p style="font-size: 18px; margin-top:0px; margin-bottom:0px;">train vast neural networks together</p>
</h1>
</div>
<div class="faded text" style="margin-top:35px; width: 100%; max-width: 900px;">
A library to train large neural networks across the internet. Imagine training one huge transformer on thousands of computers from universities, companies, and volunteers.
<br><br>
<div style="width:100%; margin: 0 auto;">
<a class="github-button" href="https://github.com/learning-at-home/hivemind" data-size="large" data-show-count="false" aria-label="Star learning-at-home/hivemind on GitHub">Code</a>
<div style="overflow: hidden; white-space: nowrap; margin: 0 auto; display: inline-block;">
<button onclick="window.open('https://arxiv.org/abs/2002.04013');"
class="arxiv_button">Paper</button>
</div>
<a href="https://twitter.com/intent/tweet?hashtags=learningathome,joinhivemind&text=Join%20the%20deep%20learning%20hivemind!%0Alearning-at-home.github.io"
class="twitter-hashtag-button" data-show-count="true" data-size="large">Tweet</a>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<script async defer src="https://buttons.github.io/buttons.js"></script>
</div>
</div>
<hr class="faded" style="width: 70%; margin-top:20px;"><br>
<div class="faded" style="margin-top:35px; display: inline-block; text-align:center;">
<div style="width: 100%; max-width: 440px; display: inline-block; vertical-align: top; text-align:left; padding-right: 5px">
<p class="faded title" style="font-size:28px; margin-bottom:12px">
Why should you care?</p>
<span class="faded text" style="margin-top: 4px;">
Larger neural networks are winning:
<ul style="text-align: left; list-style-position: inside; margin-top: 12px; margin-left: -32px;">
<li style="margin-top: 12px;">
pretrained transformers <a href=https://w4ngatang.github.io/static/papers/superglue.pdf target="_blank" rel="noopener noreferrer">dominate</a> most NLP tasks;</li>
<li style="margin-top: 12px;">
bigger CNNs <a href="https://arxiv.org/abs/1912.11370" target="_blank" rel="noopener noreferrer">perform better</a> at computer vision;</li>
<li style="margin-top: 12px;">
GPT-3 has <a href="https://arxiv.org/abs/2005.14165" target="_blank" rel="noopener noreferrer">175B</a> parameters and <a target="_blank" rel="noopener noreferrer" href="https://arxiv.org/abs/2006.16668">the race continues</a></li>
</ul>
With transfer learning, these large models can harness nearly unlimited raw data to improve performance on both <a href=https://paperswithcode.com/task/language-modelling target="_blank" rel="noopener noreferrer">academic benchmarks</a> and solve <a href=https://medium.com/towards-artificial-intelligence/crazy-gpt-3-use-cases-232c22142044 target="_blank" rel="noopener noreferrer">new unexpected</a> tasks.
<center>
<span style="margin-top: 16px; font-style: italic; font-size: 14px;">
Image credit: [1] <a href="https://arxiv.org/abs/2001.08361" target="_blank" rel="noopener noreferrer">Kaplan et al. (2020)</a>, [2,&nbsp;3] <a href="https://arxiv.org/abs/1811.06965" target="_blank" rel="noopener noreferrer">Huang et al. (2018)</a>
</span>
</center>
</span>
</div>
<div class style="width: 100%; max-width: 440px; vertical-align: middle; display: inline-block;">
<div class="carousel"
data-flickity='{ "draggable": ">1", "pageDots": false, "groupCells": true}'>
<div class="carousel-cell" style="padding-left:30px; padding-right:30px;">
<img width=340px height=250px src="kaplan1.png">
</div>
<div class="carousel-cell" style="padding-left:30px; padding-right:40px;">
<img width=320px height=250px src="gpipe1.png"></div>
<div class="carousel-cell" style="padding-left:40px; padding-right:30px;">
<img width=320px height=250px src="gpipe2.png"></div>
</div>
</div>
<p class="faded text" style="width: 100%; max-width: 900px; margin-top:16px; text-align: left">
That said, training large neural networks isn't cheap. The hardware used for the <a href="https://arxiv.org/abs/1909.08053" target="_blank" rel="noopener noreferrer">previous largest</a> language model costs over $25 million. A single training run for GPT-3 will set you back <a href="https://lambdalabs.com/blog/demystifying-gpt-3/" target="_blank" rel="noopener noreferrer">at least $4.6M</a> in cloud GPUs. As a result, researchers can't contribute to state-of-the-art deep learning models and practitioners can't build applications without <a href=https://blogs.microsoft.com/ai/openai-azure-supercomputer target="_blank" rel="noopener noreferrer">being supported</a> by a megacorporation. If&nbsp;we&nbsp;want the future of AI to be bright, it can't be private.
</p>
</div>
<br>
<div class="faded" style="margin-top:32px; width: 100%; max-width: 900px; display: inline-block; text-align: left;">
<p class="faded title" style="font-size:28px;">
What is hivemind?</p>
<br>
<p class="faded text" style="margin-top:16px;">
Hivemind is a library for decentralized training of large neural networks. In a nutshell, you want to train a neural network, but all you have is a bunch of enthusiasts with unreliable computers that communicate over the internet. Any peer may fail or leave at any time, but the training must go on. To meet this objective, hivemind models use a specialized layer type: the <b>D</b>ecentralized <b>M</b>ixture of <b>E</b>xperts (DMoE). Here's how it works:<br>
</p>
<div class="container">
<video src="dmoe_demonstration.mp4" style="width:100%; max-width:880px; min-width:320px; margin-top:12px; float:center;" controls poster="poster.png">
</video>
</div>
<br>
<div style="text-align: center">
<div style="width: 100%; max-width: 500px; vertical-align: top; display: inline-block; padding-right: 5px; text-align: left;">
<span class="faded text" style="margin-top:16px">
In a hivemind experiment, all peers:
<ul style="text-align: left; list-style-position: inside; margin-top: 16px; margin-left: -32px;">
<li style="margin-top: 12px;">
host one or more experts depending on their hardware;</li>
<li style="margin-top: 12px;">
run asynchronous training, calling experts from other peers,</li>
<li style="margin-top: 12px;">
form a Distributed Hash Table to discover each other's experts<br>
<span style="padding-left:24px">
-&nbsp;the same type of protocol that powers BitTorrent&nbsp;file&nbsp;sharing.</span>
</li>
</ul>
<p> Hivemind uses <a href=https://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf target="_blank" rel="noopener noreferrer">Kademlia</a>-based DHT that can scale to tens of thousands of peers with logarithmic search complexity.</p>
</span>
</div>
<div style="width:100%; max-width: 385px; vertical-align: top; display: inline-block; margin-top: 0px; align:center;">
<img src="hivemind_components.png" style="width:100%; max-width:240px">
</div>
<p class="faded text" style="text-align: left;">
On each forward pass, a peer first determines what "speciality" of experts is needed to process the current inputs using a small "gating function" module. Then it finds <i>k</i>&nbsp;(e.g. 4) most suitable experts from other peers in the network using the DHT protocol. Finally, it sends forward pass requests to the selected experts, collects their outputs and averages them for the final prediction. Compared to traditional architectures, the Mixture-of-Experts needs much less bandwidth as every input is only sent to a small fraction of all experts.
</p>
<div style="width:100%; max-width: 900px; vertical-align: top; display: inline-block; margin-top: 0px; align:center;">
<img src="dmoe-forward-backward.png" style="width:100%;">
</div>
<p class="faded text" style="text-align: left; margin-top:5px">
More importantly, the decentralized Mixture-of-Experts layers are inherently fault-tolerant: if some of the chosen experts fail to respond, the model will simply average the remaining ones and call that <a href=https://jmlr.org/papers/v15/srivastava14a.html target="_blank" rel="noopener noreferrer">dropout</a>. In the event that all <i>k</i> experts fail simultaneously, a peer will backtrack and find another <i>k</i> experts across the DHT. Finally, since every input is likely to be processed by different experts, hivemind peers run several <a href=https://papers.nips.cc/paper/4390-hogwild-a-lock-free-approach-to-parallelizing-stochastic-gradient-descent target="_blank" rel="noopener noreferrer">asynchronous training</a> batches to better utilize their hardware.
</p>
</div>
</div>
<br>
<div class="faded" style="margin-top:35px; width: 100%; max-width: 900px; align: center; vertical-align: top; display: inline-block; text-align:left;">
<p class="faded title" style="font-size:28px;">
What is hivemind for?
</p>
<br>
<span class="faded text" style="margin-top:15px">
Hivemind is designed for you to:
<ul style="text-align: middle; list-style-position: inside; margin-top: 16px; margin-left: -32px;">
<li style="margin-top: 12px;">
run crowdsourced deep learning using compute from volunteers or decentralized participants; </li>
<li style="margin-top: 12px;">
train neural networks on multiple servers with varying compute, bandwidth and reliability; </li>
<li style="margin-top: 12px;">
<i>[to be announced]</i> join a worldwide open deep learning experiment. </li>
</ul>
<br>
Conversely, here's what it <b>isn't</b> for:
<ul style="text-align: middle; list-style-position: inside; margin-top: 16px; margin-left: -32px;">
<li style="margin-top: 12px;">
splitting your model between 2-3 servers that you fully control: use <a href=https://pytorch.org/docs/stable/rpc.html target="_blank"rel="noopener noreferrer">torch.distributed.rpc</a>;</li>
<li style="margin-top: 12px;">
distributed training for a reliable, uniform and highly connected cluster: use <a href=https://github.com/microsoft/DeepSpeed target="_blank"rel="noopener noreferrer">DeepSpeed</a>; </li>
<li style="margin-top: 12px;">
training <span class="tooltip">small <span class="tooltiptext">More specifically, models that fit into a single worker's memory.</span></span> models with dynamically allocated of in-house workers: use <a href=https://pytorch.org/elastic/0.2.0/index.html>torch.elastic</a>.</li>
</ul>
<p style="margin-top: 16px; text-align:left">
Hivemind v0.8 is in the early alpha stage: the core functionality to train
decentralized models is there, but the inferface is still in active development.
If you want to try hivemind for yourself or contribute to its development,
take a look at the <a href=https://learning-at-home.readthedocs.io/en/latest/user/quickstart.html><u>quickstart tutorial</u></a>.
Feel free to contact us <a href=https://github.com/learning-at-home/hivemind/issues target="_blank" rel="noopener noreferrer">on github</a> with any questions, feedback and issues.
</p>
</span>
</div>
<div style="margin: 0 auto; margin-top: 0px;">
<a class="github-button" href="https://github.com/learning-at-home/hivemind" data-size="large" data-show-count="false" aria-label="Star learning-at-home/hivemind on GitHub">Code</a>
<div style="overflow: hidden; white-space: nowrap; margin: 0 auto; display: inline-block;">
<button onclick="window.open('https://arxiv.org/abs/2002.04013');"
class="arxiv_button">Paper</button>
</div>
<a href="https://twitter.com/intent/tweet?hashtags=joinhivemind,learningathome&text=Join%20the%20deep%20learning%20hivemind!%0Alearning-at-home.github.io"
class="twitter-hashtag-button" data-show-count="true" data-size="large">Tweet</a>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<script async defer src="https://buttons.github.io/buttons.js"></script>
</div>
<hr style="margin-bottom: 64px; width:0%; border: 0 solid white">
</div>
</div>
</div>
<script>
// draw background; Note: this background is based on https://codepen.io/pawelqcm/pen/oxPYox by Pawel
// Note 2: Pawel, you're awesome.
(function() {
var content_element = document.getElementById("overlay");
var canvas = document.querySelector('canvas');
var title_elem = document.getElementsByClassName("faded title")[0];
var title_text = document.getElementById("title_text");
if (screen.width < 637)
title_text.innerHTML = "<br>hivemind<br>"
ctx = canvas.getContext('2d');
if (!ctx)
console.warn("Your browser does not support canvas, content may be broken :'(");
var SENSITIVITY, SIBLINGS_LIMIT, DENSITY, TOTAL_NODES, ANCHOR_LENGTH, CURSOR_HEIGHT, CURSOR_WIDTH;
css_opts = getComputedStyle(document.documentElement);
SENSITIVITY = css_opts.getPropertyValue('--background-sensitivity') || 120;
SIBLINGS_LIMIT = css_opts.getPropertyValue('--background-siblings') || 7;
NODE_DENSITY = css_opts.getPropertyValue('--background-node-density') || 6;
CURSOR_WIDTH = css_opts.getPropertyValue('--background-cursor-width') || 250;
CURSOR_HEIGHT = css_opts.getPropertyValue('--background-cursor-height') || 250;
CURSOR_VERTICAL_SHRINK = css_opts.getPropertyValue('--background-cursor-vertical-shrink') || 0.1;
SPEED_COEF = css_opts.getPropertyValue('--background-speed') || 1;
ENERGY_DECAY = css_opts.getPropertyValue('--energy-decay') || 2;
SHOW_IF_WIDER_THAN = css_opts.getPropertyValue('--background-show-if-wider-than') || 500;
MOVE_ON_CURSOR = css_opts.getPropertyValue('--background-move-on-cursor').includes("true") || false;
var nodes = [];
choice = (choices => choices[Math.floor(Math.random() * choices.length)])
sample_color = () => choice([[40, 40, 40], [133, 133, 133]])
ANCHOR_LENGTH = 20;
var cursor = {x: 0, y: 0};
function centralize_cursor() {
var rect = document.getElementById("bug-logo").getBoundingClientRect()
var window_left = window.pageXOffset || document.documentElement.scrollLeft;
var window_top = window.pageYOffset || document.documentElement.scrollTop;
cursor.x = window_left + rect.left + rect.width / 2;
cursor.y = window_top + rect.top + rect.height / 2;
}
function Node(x, y) {
this.anchorX = x;
this.anchorY = y;
this.x = Math.random() * (x - (x - ANCHOR_LENGTH)) + (x - ANCHOR_LENGTH);
this.y = Math.random() * (y - (y - ANCHOR_LENGTH)) + (y - ANCHOR_LENGTH);
this.vx = (Math.random() * 2 - 1) * SPEED_COEF;
this.vy = (Math.random() * 2 - 1) * SPEED_COEF;
this.energy = Math.random() * 100;
this.radius = Math.random();
this.siblings = [];
[this.r, this.g, this.b] = sample_color()
this.brightness = 0;
}
Node.prototype.drawNode = function() {
var color = `rgba(${this.r}, ${this.g}, ${this.b}, ${this.brightness})`;
ctx.beginPath();
ctx.arc(this.x, this.y, 2 * this.radius + 2 * this.siblings.length / SIBLINGS_LIMIT, 0, 2 * Math.PI);
ctx.fillStyle = color;
ctx.fill();
};
Node.prototype.drawConnections = function() {
for (var i = 0; i < this.siblings.length; i++) {
var color = `rgba(133, 133, 133, ${this.brightness})`;
ctx.beginPath();
ctx.moveTo(this.x, this.y);
ctx.lineTo(this.siblings[i].x, this.siblings[i].y);
ctx.lineWidth = 1 - calcDistance(this, this.siblings[i]) / SENSITIVITY;
ctx.strokeStyle = color;
ctx.stroke();
}
};
Node.prototype.moveNode = function() {
this.energy -= ENERGY_DECAY;
if (this.energy < 1) {
this.energy = Math.random() * 100;
if (this.x - this.anchorX < -ANCHOR_LENGTH) {
this.vx = Math.random() * SPEED_COEF;
} else if (this.x - this.anchorX > ANCHOR_LENGTH) {
this.vx = Math.random() * -SPEED_COEF;
} else {
this.vx = Math.random() * SPEED_COEF * 2 - SPEED_COEF;
}
if (this.y - this.anchorY < -ANCHOR_LENGTH) {
this.vy = Math.random() * SPEED_COEF;
} else if (this.y - this.anchorY > ANCHOR_LENGTH) {
this.vy = Math.random() * -SPEED_COEF;
} else {
this.vy = Math.random() * SPEED_COEF * 2 - SPEED_COEF;
}
}
relative_speed_rate = Math.min(canvas.height / 100, 10.0)
this.x += this.vx * this.energy * relative_speed_rate;
this.y += this.vy * this.energy * relative_speed_rate;
};
function initNodes() {
centralize_cursor();
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (canvas.width >= SHOW_IF_WIDER_THAN)
total_nodes = Math.round(NODE_DENSITY * (canvas.width / 100 * canvas.height / 100));
else
total_nodes = 0;
nodes = [];
for (var i = 0; i < total_nodes; i++)
nodes.push(new Node(50 + Math.random() * (canvas.width - 100),
5 + Math.random() * (canvas.height - 10)));
}
function calcDistance(node1, node2) {
return Math.sqrt(Math.pow(node1.x - node2.x, 2) + (Math.pow(node1.y - node2.y, 2)));
}
function findSiblings() {
var node1, node2, distance;
for (var i = 0; i < nodes.length; i++) {
node1 = nodes[i];
node1.siblings = [];
for (var j = 0; j < nodes.length; j++) {
node2 = nodes[j];
if (node1 !== node2) {
distance = calcDistance(node1, node2);
if (distance < SENSITIVITY) {
if (node1.siblings.length < SIBLINGS_LIMIT) {
node1.siblings.push(node2);
} else {
var node_sibling_distance = 0;
var max_distance = 0;
var s;
for (var k = 0; k < SIBLINGS_LIMIT; k++) {
node_sibling_distance = calcDistance(node1, node1.siblings[k]);
if (node_sibling_distance > max_distance) {
max_distance = node_sibling_distance;
s = k;
}
}
if (distance < max_distance) {
node1.siblings.splice(s, 1);
node1.siblings.push(node2);
}
}
}
}
}
}
}
function redrawScene() {
resizeWindow();
ctx.clearRect(0, 0, canvas.width, canvas.height);
findSiblings();
var i, node, distance;
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
scaled_distance = calcDistance({x: cursor.x / CURSOR_WIDTH, y: cursor.y / CURSOR_HEIGHT},
{x: node.x / CURSOR_WIDTH, y: node.y / CURSOR_HEIGHT});
node.brightness = Math.max(1 - scaled_distance, 0);
}
for (i = 0; i < nodes.length; i++) {
node = nodes[i];
if (node.brightness) {
node.drawConnections();
node.drawNode();
}
node.moveNode();
}
requestAnimationFrame(redrawScene);
}
function initHandlers() {
document.addEventListener('resize', resizeWindow);
document.addEventListener('orientationchange', resizeWindow);
if (MOVE_ON_CURSOR) {
document.addEventListener('mousemove', moveHandler);
document.addEventListener('touchmove', moveHandler);
}
}
function resizeWindow(evt) {
var new_width, new_height;
new_width = Math.round(Math.max(title_elem.getBoundingClientRect().right, window.innerWidth))
if (!MOVE_ON_CURSOR)
new_height = Math.round(title_elem.getBoundingClientRect().top - canvas.getBoundingClientRect().top);
else
new_height = Math.round(Math.max(
content_element.offsetHeight, content_element.scrollHeight,
content_element.clientHeight, window.innerHeight));
if (canvas.width != new_width || canvas.height != new_height) {
canvas.width = new_width;
canvas.height = new_height;
initNodes();
}
if (!MOVE_ON_CURSOR)
centralize_cursor();
}
function moveHandler(evt) {
if (evt.type == "mousemove") {
cursor.x = window.pageXOffset + evt.clientX;
cursor.y = window.pageYOffset + evt.clientY;
}
else { // touch event
cursor.x = window.pageXOffset + evt.changedTouches[0].clientX;
cursor.y = window.pageYOffset + evt.changedTouches[0].clientY;
}
}
initHandlers();
initNodes();
redrawScene();
})();
</script>
</body>
</html>