Skip to content

Commit

Permalink
first attempt at flickering but not pleased..
Browse files Browse the repository at this point in the history
  • Loading branch information
amphinomid committed Jun 10, 2024
1 parent 3310f0d commit 33b2887
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,27 @@ function xor(a, b) {
return (a + b) % 2;
}

function flicker_text(text_div) {
num_flickers = Math.random() * 3 + 1;
for (let i = 0; i < num_flickers; i++) {
setTimeout(() => {
text_div.style.visibility = "hidden";
}, Math.random() * 50);
setTimeout(() => {
text_div.style.visibility = "visible";
}, Math.random() * 50);
}
}

function add_text(bit, x, y) {
const new_div = document.createElement("div");
const new_text = document.createTextNode(bit);
new_div.appendChild(new_text);
const parent_div = document.getElementById("parent");
parent_div.appendChild(new_div);
new_div.style.position = "absolute";
new_div.style.left = x + "px";
new_div.style.top = y + "px";
new_div.style.left = (x - 2.5) + "px";
new_div.style.top = (y - 2.5) + "px";
return new_div;
}

Expand Down Expand Up @@ -59,3 +71,13 @@ image.onload = function() {
texts.push(texts_row);
}
};

// Make texts flicker indefinitely
window.setInterval(function() {
for (let i = 0; i < texts.length; i++) {
for (let j = 0; j < texts[i].length; j++) {
if (Math.random() > 0.5) continue;
flicker_text(texts[i][j]);
}
}
}, 1000);

0 comments on commit 33b2887

Please sign in to comment.