-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
169 lines (152 loc) · 4.8 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
<!DOCTYPE html>
<html>
<head>
<title>Synapse</title>
<!--
<link href="css/bootstrap.min.css" rel="stylesheet">
-->
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="scripts.js"></script>
</head>
<body>
<div id="title_band">
<div id="title">synapse</div>
<div id="file-drop" style=" border:3px solid white;
height:300px;
width: 50%;
margin: auto;
margin-top: 50px;
text-align: center;
font-size: 30px;
color: #ffffff;
padding-top: 110px;
border-radius: 25px;
background-color:rgba(0, 0, 0, 0);
">Drop your HTML file here to get an <i>instant</i> shareable link!</div>
</div>
<canvas></canvas>
<script>
var canvas = document.querySelector("canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var ctx = canvas.getContext("2d");
var TAU = 2 * Math.PI;
times = [];
function loop() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
update();
draw();
requestAnimationFrame(loop);
}
function Ball (startX, startY, startVelX, startVelY) {
this.x = startX || Math.random() * canvas.width;
this.y = startY || Math.random() * canvas.height;
this.vel = {
x: startVelX || Math.random() * 2 - 1,
y: startVelY || Math.random() * 2 - 1
};
this.update = function(canvas) {
if (this.x > canvas.width + 50 || this.x < -50) {
this.vel.x = -this.vel.x;
}
if (this.y > canvas.height + 50 || this.y < -50) {
this.vel.y = -this.vel.y;
}
this.x += this.vel.x;
this.y += this.vel.y;
};
this.draw = function(ctx, can) {
ctx.beginPath();
ctx.globalAlpha = .4;
ctx.fillStyle = '#448fda';
ctx.arc((0.5 + this.x) | 0, (0.5 + this.y) | 0, 3, 0, TAU, false);
ctx.fill();
}
}
var balls = [];
for (var i = 0; i < canvas.width * canvas.height / (65*65); i++) {
balls.push(new Ball(Math.random() * canvas.width, Math.random() * canvas.height));
}
var lastTime = Date.now();
function update() {
var diff = Date.now() - lastTime;
for (var frame = 0; frame * 16.6667 < diff; frame++) {
for (var index = 0; index < balls.length; index++) {
balls[index].update(canvas);
}
}
lastTime = Date.now();
}
var mouseX = -1e9, mouseY = -1e9;
document.addEventListener('mousemove', function(event) {
mouseX = event.clientX;
mouseY = event.clientY;
});
function distMouse(ball) {
return Math.hypot(ball.x - mouseX, ball.y - mouseY);
}
function draw() {
ctx.globalAlpha=1;
ctx.fillStyle = '#000000';
ctx.fillRect(0,0,canvas.width, canvas.height);
for (var index = 0; index < balls.length; index++) {
var ball = balls[index];
ball.draw(ctx, canvas);
ctx.beginPath();
for (var index2 = balls.length - 1; index2 > index; index2 += -1) {
var ball2 = balls[index2];
var dist = Math.hypot(ball.x - ball2.x, ball.y - ball2.y);
if (dist < 100) {
ctx.strokeStyle = "#448fda";
ctx.globalAlpha = 1 - (dist > 100 ? .8 : dist / 150);
ctx.lineWidth = "2px";
ctx.moveTo((0.5 + ball.x) | 0, (0.5 + ball.y) | 0);
ctx.lineTo((0.5 + ball2.x) | 0, (0.5 + ball2.y) | 0);
}
}
ctx.stroke();
}
}
// Start
loop();
</script>
<script src="https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js"></script>
<script>
var file_drop = document.getElementById('file-drop');
file_drop.addEventListener(
'dragover',
function handleDragOver(evt) {
evt.stopPropagation()
evt.preventDefault()
evt.dataTransfer.dropEffect = 'copy'
},
false
)
file_drop.addEventListener(
'drop',
function(evt) {
evt.stopPropagation()
evt.preventDefault()
var files = evt.dataTransfer.files // FileList object.
var file = files[0] // File object.
/*
CODE Takes in a file as input and seeds
*/
var client = new WebTorrent()
client.seed(files, function (torrent) {
document.getElementById("file-drop").innerHTML = "It's Live! <br /> https://nikhil-bose.github.io/Synapse/recieve.html?hash=" + torrent.infoHash;
document.getElementById("file-drop").style.paddingTop = "50px";
/*
alert('https://nikhil-bose.github.io/Synapse/recieve.html?hash=' + torrent.infoHash)
*/
})
},
false
)
</script>
</body>
</html>