Last active
June 16, 2021 12:11
-
-
Save JamesIves/af5910fc48a218c9a52b99e6a5b3630a to your computer and use it in GitHub Desktop.
Basic interpretation of the Quake light flicker in JavaScript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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