-
Notifications
You must be signed in to change notification settings - Fork 0
/
404.html
105 lines (86 loc) · 3.06 KB
/
404.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
---
layout: page
title: 404
sitemap:
exclude: 'yes'
---
<h2 class="go-home">
I suggest you <a href="/">going home</a>, it's 404 and it's getting dark!
</h2>
<!-- Adding the glitch effect -->
<script>
document.getElementsByTagName('body')[0].classList.add('glitch');
// TV static noise
(function() {
"use strict";
var canvas = document.querySelector("#tv"),
context = canvas.getContext("2d"),
scaleFactor = 2.5, // Noise size
samples = [],
sampleIndex = 0,
scanOffsetY = 0,
scanSize = 0,
FPS = 50,
scanSpeed = FPS * 15, // 15 seconds from top to bottom
SAMPLE_COUNT = 10;
window.onresize = function() {
canvas.width = canvas.offsetWidth / scaleFactor;
canvas.height = canvas.width / (canvas.offsetWidth / canvas.offsetHeight);
scanSize = (canvas.offsetHeight / scaleFactor) / 3;
samples = []
for(var i = 0; i < SAMPLE_COUNT; i++)
samples.push(generateRandomSample(context, canvas.width, canvas.height));
};
function interpolate(x, x0, y0, x1, y1) {
return y0 + (y1 - y0)*((x - x0)/(x1 - x0));
}
function generateRandomSample(context, w, h) {
var intensity = [];
var random = 0;
var factor = h / 50;
var intensityCurve = [];
for(var i = 0; i < Math.floor(h / factor) + factor; i++)
intensityCurve.push(Math.floor(Math.random() * 15));
for(var i = 0; i < h; i++) {
var value = interpolate((i/factor), Math.floor(i / factor), intensityCurve[Math.floor(i / factor)], Math.floor(i / factor) + 1, intensityCurve[Math.floor(i / factor) + 1]);
intensity.push(value);
}
var imageData = context.createImageData(w, h);
for(var i = 0; i < (w * h); i++) {
var k = i * 4;
var color = Math.floor(36 * Math.random());
// Optional: add an intensity curve to try to simulate scan lines
color += intensity[Math.floor(i / w)];
imageData.data[k] = imageData.data[k + 1] = imageData.data[k + 2] = color;
imageData.data[k + 3] = 45;
}
return imageData;
}
function render() {
context.putImageData(samples[Math.floor(sampleIndex)], 0, 0);
sampleIndex += 30 / FPS; // 1/FPS == 1 second
if(sampleIndex >= samples.length) sampleIndex = 0;
var grd = context.createLinearGradient(0, scanOffsetY, 0, scanSize + scanOffsetY);
grd.addColorStop(0, 'rgba(45,45,45,0)');
grd.addColorStop(0.1, 'rgba(45,45,45,0)');
grd.addColorStop(0.2, 'rgba(45,45,45,0.2)');
grd.addColorStop(0.3, 'rgba(255,255,255,0.0)');
grd.addColorStop(0.45, 'rgba(255,255,255,0.1)');
grd.addColorStop(0.5, 'rgba(255,255,255,1.0)');
grd.addColorStop(0.55, 'rgba(255,255,255,0.55)');
grd.addColorStop(0.6, 'rgba(245,245,245,0.25)');
grd.addColorStop(0.8, 'rgba(255,255,255,0.15)');
grd.addColorStop(1, 'rgba(45,45,45,0)');
context.fillStyle = grd;
context.fillRect(0, scanOffsetY, canvas.width, scanSize + scanOffsetY);
context.globalCompositeOperation = "lighter";
scanOffsetY += (canvas.height / scanSpeed);
if(scanOffsetY > canvas.height) scanOffsetY = -(scanSize / 2);
window.setTimeout(function() {
window.requestAnimationFrame(render);
}, 1000 / FPS);
}
window.onresize();
window.requestAnimationFrame(render);
})();
</script>