Skip to content

Instantly share code, notes, and snippets.

@TheSnowfield
Last active January 30, 2022 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheSnowfield/39957c8fae5b9a26b2d22ac68b4577f1 to your computer and use it in GitHub Desktop.
Save TheSnowfield/39957c8fae5b9a26b2d22ac68b4577f1 to your computer and use it in GitHub Desktop.
Braille character in JavaScript

Code snippet

function braille_pattern(blocks)
{
    if(!(blocks instanceof Array) || blocks.length > 8 || blocks.length < 0) 
        throw new TypeError("Only accept an array in max of 8 elements with 0/1 or true/false.");

    // value table
    const table = [1, 2, 4, 64, 8, 16, 32, 128];

    // codepoint offset
    let offset = 0;

    // calculate
    blocks.forEach((val, i) => {
       if(val == 1 || val == true) offset += table[i];
    });

    // eval to character
    return String.fromCodePoint(0x2800 + offset);
}

Example

braille_pattern([1,1,1]); => ⠇('\u2807')
braille_pattern([1,1,1,0,0,1]); => ⠗('\u2817')
braille_pattern([1,1,1,1,1,1,1,1]); => ⣿('\u28ff')

Graphs

⡏⣭⡍⡇⠄⠅⡃⡏⣭⡍⡇
⠧⠭⠥⠇⡜⡞⠅⠧⠭⠥⠇
⠻⡥⠹⢽⢇⣱⣹⢵⡠⢵⠆
⡥⠥⠥⡍⣆⠊⠌⡋⠼⢨⠅
⡇⠿⠇⡇⣵⣳⣱⢵⣉⢜⠅
⠉⠉⠉⠁⠉⠉⠈⠉⠀⠉⠁

I tried to use a braille pattern art to make a scannable qr code.
but clearly, this can not take any sense. cuz the line height.

Reference

https://unicode-table.com/en/blocks/braille-patterns/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment