canvas lines connect dottes
by Osama Qassar
HTML
<h1>OSAMA QASSAR</h1>
<h2>
<a href="#">OSAMA QASSAR</a>
</h2>
<canvas id="bgDots"></canvas>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
CSS
@import url(https://fonts.googleapis.com/css?family=Merriweather:700);
body, html {
padding: 0;
margin: 0;
background:#ccc;
}
h1 {
font-size: 4em;
font-weight: 700;
text-align: center;
}
canvas{
z-index:999;
position:absolute;
left:0;
top:0;
}
canvas, canvas *, canvas:hover{
pointer-events:none
}
JavaScript
function documentHeight() {
return Math.max(
document.documentElement.clientHeight,
document.body.scrollHeight,
document.documentElement.scrollHeight,
document.body.offsetHeight,
document.documentElement.offsetHeight
);
}
function documentWidth() {
return Math.max(
document.documentElement.clientWidth,
document.body.scrollWidth,
document.documentElement.scrollWidth,
document.body.offsetWidth,
document.documentElement.offsetWidth
);
}
/*window.onload = function(){
document.getElementById('#bgDots').style.height = documentHeight()+"px";
}*/
var canvas = document.getElementById('bgDots');
canvas.width = documentWidth()//window.innerWidth;
canvas.height = documentHeight()//window.innerHeight;
var ctx = canvas.getContext("2d");
var TAU = 2 * Math.PI;
var movSpeed = 50000;
var lineColor = "#eee";
var lineSize = 10
var linesDensity = 90;
var dotColor = "#000";
var dotAlpha = 0.1;
var dotSize = 3;
var bgAlpha = 0;
var bgColor = "#ccc";
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 = dotAlpha;
ctx.fillStyle = dotColor;
ctx.arc((0.5 + this.x) | 0, (0.5 + this.y) | 0, dotSize, 0, TAU, false);
ctx.fill();
}
}
var balls = [];
for (var i = 0; i < canvas.width *...