57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
|
let inactivityTime = function() {
|
||
|
let time;
|
||
|
window.onload = resetTimer;
|
||
|
document.onmousemove = resetTimer;
|
||
|
document.onkeypress = resetTimer;
|
||
|
function resetTimer() {
|
||
|
clearTimeout(time);
|
||
|
time = setTimeout(matrix, 2000)
|
||
|
}
|
||
|
};
|
||
|
window.onload = function() {
|
||
|
inactivityTime();
|
||
|
}
|
||
|
|
||
|
|
||
|
function matrix(){
|
||
|
let canvasnodecreation = document.createElement('canvas')
|
||
|
document.body.innerHTML=''
|
||
|
document.body.appendChild(canvasnodecreation)
|
||
|
var canvas = document.querySelector('canvas'),
|
||
|
ctx = canvas.getContext('2d');
|
||
|
|
||
|
canvas.width = window.innerWidth;
|
||
|
canvas.height = window.innerHeight;
|
||
|
|
||
|
var letters = '010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101';
|
||
|
letters = letters.split('');
|
||
|
|
||
|
|
||
|
var fontSize = 10,
|
||
|
columns = canvas.width / fontSize;
|
||
|
|
||
|
|
||
|
var drops = [];
|
||
|
for (var i = 0; i < columns; i++) {
|
||
|
drops[i] = 1;
|
||
|
}
|
||
|
|
||
|
|
||
|
function draw() {
|
||
|
ctx.fillStyle = 'rgba(0, 0, 0, .1)';
|
||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||
|
for (var i = 0; i < drops.length; i++) {
|
||
|
var text = letters[Math.floor(Math.random() * letters.length)];
|
||
|
ctx.fillStyle = '#0f0';
|
||
|
ctx.fillText(text, i * fontSize, drops[i] * fontSize);
|
||
|
drops[i]++;
|
||
|
if (drops[i] * fontSize > canvas.height && Math.random() > .95) {
|
||
|
drops[i] = 0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
setInterval(draw, 33);
|
||
|
}
|