Last active
July 3, 2021 21:03
-
-
Save raylee/be52a692e0496727e04566dcfcb99023 to your computer and use it in GitHub Desktop.
Translate a dot pattern to the correct Unicode braille codepoint
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
package main | |
import "fmt" | |
type BrailleDots [4][2]bool | |
func (b BrailleDots) String() string { | |
var braille uint32 = 0x2800 | |
set := [4][2]uint32{ | |
{0x01, 0x08}, | |
{0x02, 0x10}, | |
{0x04, 0x20}, | |
{0x40, 0x80}, | |
} | |
for y := 0; y < 4; y++ { | |
for x := 0; x < 2; x++ { | |
if b[y][x] { | |
braille |= set[y][x] | |
} | |
} | |
} | |
return string(rune(braille)) | |
} | |
func main() { | |
d := &BrailleDots{ | |
{true, false}, | |
{true, false}, | |
{true, false}, | |
{true, false}, | |
} | |
fmt.Println(d) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment