-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencode.exs
More file actions
executable file
·32 lines (30 loc) · 864 Bytes
/
encode.exs
File metadata and controls
executable file
·32 lines (30 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/env elixir
colmax = 32
rowmax = 7
fontw = 6
fonth = 8
IO.binread(:all)
|> String.split("\n")
|> Enum.map(&String.trim/1)
|> Enum.reject(fn s -> s == "" end)
|> Enum.reject(fn s -> s == "P1" end)
|> Enum.reject(fn s -> s == "192 56" end)
|> Enum.reject(fn s -> String.starts_with?(s, "#") end)
|> Enum.join()
|> String.to_charlist()
|> Enum.chunk_every(colmax * fontw)
|> Enum.zip()
|> Enum.map(&Tuple.to_list/1)
|> Enum.map(&Enum.reverse/1)
|> Enum.map(&Enum.chunk_every(&1, fonth))
|> Enum.map(&Enum.reverse/1)
|> Enum.zip()
|> Enum.flat_map(&Tuple.to_list/1)
|> Enum.map(&to_string/1)
|> Enum.map(fn bin -> String.to_integer(bin, 2) end)
|> Enum.map(fn int -> Integer.to_string(int, 16) end)
|> Enum.map(fn hex -> "0x#{String.pad_leading(hex, 2, "0")}" end)
|> Enum.chunk_every(6)
|> Enum.map(&Enum.join(&1, ", "))
|> Enum.join(",\n")
|> IO.puts()