Skip to content

Instantly share code, notes, and snippets.

@ManasJayanth
Created August 31, 2015 05:49
Show Gist options
  • Select an option

  • Save ManasJayanth/a71dbed01b41ec6f3374 to your computer and use it in GitHub Desktop.

Select an option

Save ManasJayanth/a71dbed01b41ec6f3374 to your computer and use it in GitHub Desktop.
My crappy attempt the matrix screen
<html>
<head>
<style>
html, body {
height: 100%;
width: 100%;
margin: 0;
font-size: 100%;
background-color: #000000;
color: green;
}
#container {
height: 100%;
width: 100%;
}
.column {
float: left;
margin: 0 1px 0 1px;
word-wrap: break-word;
line-height: 1;
width: 16px;
letter-spacing: 1px;
}
</style>
</head>
<body>
<div id="container">
</div>
<script type="text/javascript">
window.addEventListener('load', function () {
function renderTemplate(template, obj) {
var key;
return template.replace(/\{\{.+}\}/g, function (m) {
m = m.replace(/[\{|\}]/g, '');
return obj[m] || '';
});
}
function rndChar() {
return Math.floor(Math.random() * 16).toString(16).toUpperCase();
}
var screenWidth = window.screen.availWidth;
/**
* Has the following properties
* - dom
* - computedStyles
*/
var container = (function () {
var obj = {};
obj.dom = document.querySelector('#container');
obj.computedStyles = window.getComputedStyle(obj.dom, null);
obj.fontSize = (function () {
var size = obj.computedStyles.fontSize;
return +size.substring(0, size.length - 2);
}());
return obj;
}());
var columns = {};
columns.width = container.fontSize;
columns.no = Math.floor(screenWidth / (columns.width)) - 10;
columns.template = '<div class="column" style="width:16px">{{text}}</div>';
columns.html = [];
columns.style = {
float: 'left',
width: columns.width,
'text-align': 'center'
};
var screenBuf = [];
for (var i = 0, ii = columns.no; i < ii; i += 1) {
screenBuf[i] = '0';
for (var j = 0, jj = columns.no; j < jj; j += 1) {
screenBuf[i] += '0';
}
}
var indices = [], mid = Math.floor((0 + columns.no - 1) / 2);
indices.push(mid);
var i = 1, counter = mid;
while (counter) {
indices.push(mid - i);
indices.push(mid + i);
i += 1;
counter -= 1;
}
if (!(columns.no % 2)) {
indices.push(columns.no - 1);
}
var j;
// for (i = 1; i <= columns.no; ++i) {
// for (j = 0; j < i; ++j) {
// screenBuf[indices[j]] = rndChar() + screenBuf[indices[j]] ;
// //flush screen buffer to dom
// var html;
// for(i = 0; i < columns.no; ++i) {
// html += renderTemplate(columns.template, {text: screenBuf[i]});
// }
// columns.html.join('');
// container.dom.innerHTML = html;
// }
// }
// intI = 1;
// setInterval(function () {
// intI += 1;
// for (j = 0; j < intI; ++j) {
// screenBuf[indices[j]] += rndChar();
// }
// columns.generate();
// },200);
intI = 1;
setInterval(function () {
if (intI < columns.no) {
z = intI;
} else {
z = columns.no;
}
for (j = 0; j < z; ++j) {
var tempStr = screenBuf[indices[j]];
var temparray = tempStr.split('');
temparray.unshift(rndChar());
temparray.pop();
screenBuf[indices[j]] = temparray.join('');
}
//flush screen buffer to dom
var html = '';
for(i = 0; i < columns.no; ++i) {
html += renderTemplate(columns.template, {text: screenBuf[i]});
}
// console.log(html);
// console.log('---------');
container.dom.innerHTML = html;
intI += 1;
},1);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment