Skip to content

Instantly share code, notes, and snippets.

@HairyFotr
Last active December 28, 2015 21:58
Show Gist options
  • Save HairyFotr/7567945 to your computer and use it in GitHub Desktop.
Save HairyFotr/7567945 to your computer and use it in GitHub Desktop.
Give it a bit-string, and get out a UTF Braille rendering, e.g. https://en.wikipedia.org/wiki/Arecibo_message#Message_as_binary_string.5B4.5D
def encode(a: String, zero: Char = '0'): String = {
val bits = a.split("\n").map { line => line.map { _ != zero }.toArray }
val offsets = Array.ofDim[Int](bits.size/4+1, bits.head.size/2+1)
for(i <- 0 until bits.size; j <- 0 until bits.head.size) if(bits(i)(j)) offsets(i/4)(j/2) += (if(i%4 == 3) 0x40*(j%2 + 1) else math.pow(2, i%4 + (j%2)*3).toInt)
offsets.map { row => row.map { off => Character.toChars(0x2800 + off).head }.mkString }.mkString("\n")
}
@HairyFotr
Copy link
Author

⡄⡂⡆⡁⡅⡃⡇⡠⢠⠄⡢⠀
⠀⠀⠀⠀⠀⣤⢲⠀⠀⠀⠀⠀
⣀⠀⠀⣀⡘⠚⣚⠀⠀⣀⠀⠀
⠷⠴⠄⠴⠦⠄⠶⠭⠄⠷⠴⠄
⣀⣈⡄⠀⠀⠀⠀⠀⠀⣀⣈⡄
⣖⢀⠀⠒⣄⠀⢒⣂⠀⣖⢀⠀
⠉⠩⠁⠉⠉⣥⠉⠉⠁⠉⠩⠁
⠒⡒⠃⠀⠀⢿⠀⠀⠀⠒⡒⠃
⠀⠈⠒⠤⠀⣻⠀⣀⠤⠊⠀⠀
⠀⡠⠒⠉⠀⣞⠀⠀⠉⠢⡀⠀
⠘⢄⠀⠀⠀⠝⠀⠀⣀⠔⠁⠀
⠀⡆⠉⠒⣂⣆⡒⠉⠀⠀⠀⠀
⠄⠥⠄⠊⢸⢿⠈⠂⢱⣟⢾⡇
⠀⠇⠀⠀⠼⠸⠄⠀⠘⠋⠉⠁
⠀⠿⠇⠂⠂⠁⠂⡆⡆⠆⠆⠂
⠀⢀⡤⠖⠛⠛⠓⠦⣄⠀⠀⠀
⢰⠋⢸⠢⡀⠀⡠⢺⠈⢳⠀⠀
⠀⠀⠸⢀⠈⡊⡀⠸⠀⠀⠀⠀
⠈⠉⠁⠈⠉⠉⠈⠀⠉⠉⠀⠀

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