Last active
May 20, 2025 20:38
-
-
Save theraccoonbear/671e026d2545bf97b63fcd5de8e548d7 to your computer and use it in GitHub Desktop.
Generate markup of a free-speech-flag-esque representation of arbitrary text.
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 generateFlagHTML(text) { | |
| // Convert text to hex | |
| const hex = Array.from(text) | |
| .map(c => c.charCodeAt(0).toString(16).padStart(2, '0')) | |
| .join(''); | |
| // Pad hex string to multiple of 6 (RGB triplet) | |
| const paddedHex = hex.padEnd(Math.ceil(hex.length / 6) * 6, '0'); | |
| // Chunk into RGB hex triplets | |
| const colors = paddedHex.match(/.{6}/g) || []; | |
| // Generate divs for each color | |
| const flagDivs = colors.map(color => | |
| `<div style="width: 20px; height: 100px; padding: 0px; margin: 0px; display: inline-block; background-color: #${color};"></div>` | |
| ).join('\n'); | |
| return flagDivs; | |
| } | |
| // Example usage: | |
| document.body.innerHTML = document.body.innerHTML + generateFlagHTML("Free Speech!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment