Skip to content

Instantly share code, notes, and snippets.

@raylee
Last active July 3, 2021 21:03
Show Gist options
  • Save raylee/be52a692e0496727e04566dcfcb99023 to your computer and use it in GitHub Desktop.
Save raylee/be52a692e0496727e04566dcfcb99023 to your computer and use it in GitHub Desktop.
Translate a dot pattern to the correct Unicode braille codepoint
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