Skip to content

Instantly share code, notes, and snippets.

@JamesIves
Last active June 16, 2021 12:11
Show Gist options
  • Save JamesIves/af5910fc48a218c9a52b99e6a5b3630a to your computer and use it in GitHub Desktop.
Save JamesIves/af5910fc48a218c9a52b99e6a5b3630a to your computer and use it in GitHub Desktop.
Basic interpretation of the Quake light flicker in JavaScript.
const flickerString = "mmamammmmammamamaaamammma";
const flickerInterval = 500;
const pauseExecution = (timeout) => {
return new Promise((resolve) =>
setTimeout(() => {
resolve();
}, timeout)
);
}
const quakeLightFlicker = async () => {
let index = 0;
while (true) {
await pauseExecution(flickerInterval);
if (flickerString[index] === "a") {
console.log("Current Pattern: a");
// Presumably you could do something with lights here?
} else {
console.log("Current Pattern: m");
}
index = (index + 1) % flickerString.length;
}
};
quakeLightFlicker();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment