Created
November 22, 2016 15:24
-
-
Save kenchris/ef26b8223654e181ef9e403e3b21f7e1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function parseColor(colorStr) { | |
if (!this.div) { | |
this.div = document.createElement('div'); | |
this.div.style.hidden = true; | |
document.body.appendChild(this.div) | |
} | |
this.div.style.color = colorStr; | |
if (this.div.style.color === "") | |
this.div.style.color = `#${colorStr}`; | |
let style = window.getComputedStyle(this.div); | |
let colors = style.color.match(/\d+/g).map(a => parseInt(a, 10)); | |
return new Uint8Array(colors); | |
} | |
function withdelay(values, delay) { | |
return { | |
[Symbol.iterator]: function* () { | |
for (let i of values) { | |
yield new Promise(resolve => { | |
setTimeout(_ => resolve(i), delay); | |
}); | |
} | |
} | |
}; | |
} | |
async function run() { | |
for (let color of withdelay(["red", "purple", "blue"], 500)) { | |
console.log(parseColor(await color)); | |
} | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment