JSFiddle - React, Tailwind, and code Playground
CSS
body { position:relative; height:100% ; background:#000; overflow:hidden; }
html { height: 100%; }
div { width : 4px; height : 4px; border-radius : 100%; position : absolute; }
JavaScript
var NUM = 200,
THRESHOLDNUM = 60;
// returns any random digits you need
// gets a reasonable random() calling frequency
var rands = (function(i) {
var obj = {
getRandomDigit: function() {
if (!(this.rands && this.rands.length > 0)) {
this.rands = Math.random().toString().substr(2).split("");
}
return this.rands.shift();
},
getRandomDigits: function(requireNumbers) {
var str = "",
n = requireNumbers;
while (n > 0) {
str += this.getRandomDigit();
n--;
}
return str;
}
};
return function(needs) {
return obj.getRandomDigits(needs);
};
})(THRESHOLDNUM);
// creates enough divs
var htmls = [];
for (i = 0; i < NUM; i++) {
var a = document.createElement("div");
a.style.top = rands(2) + "%";
a.style.left = rands(2) + "%";
a.style.backgroundColor = "rgb(" + rands(2) + "%," + rands(2) + "%," + rands(2) + "%)";
htmls.push(a.outerHTML);
}
document.body.innerHTML = htmls.join("");
var allnodes = document.body.childNodes;
var repaint = function() {
for (var i = 0; i < NUM; i++) {
allnodes[i].style.boxShadow = "0 0 " + rands(2) + "px #FFFFFF" ;
}
} ;
setInterval(function(){
repaint() ;
} , 16) ;
// (function run() {
// repaint() ;
// requestAnimationFrame(run);
// })();
// (function run() {
// repaint() ;
// setTimeout(run , 13);
// })();