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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/usr/bin/env lua
local eyes = require "eyes"
local format = require "format"
local reading = require "reading"
local vec2 = require "cpml".vec2
local readout = {
[0] = vec2.new{ 0, 0},
[1] = vec2.new{ 0, 1},
[2] = vec2.new{ 1, 0},
[3] = vec2.new{ 0, -1},
[4] = vec2.new{-1, 0},
}
local translation = {
[0] = vec2.new{0, 0},
[1] = vec2.new{0, 1},
[2] = vec2.new{0.447, 0.894},
[3] = vec2.new{0.707, 0.707},
[4] = vec2.new{0.894, 0.447},
[5] = vec2.new{1, 0},
[6] = vec2.new{0.894, -0.447},
[7] = vec2.new{0.707, -0.707},
[8] = vec2.new{0.447, -0.894},
[9] = vec2.new{0, -1},
[10] = vec2.new{-0.447, -0.894},
[11] = vec2.new{-0.707, -0.707},
[12] = vec2.new{-0.894, -0.447},
[13] = vec2.new{-1, 0},
[14] = vec2.new{-0.894, 0.447},
[15] = vec2.new{-0.707, 0.707},
[16] = vec2.new{-0.447, 0.894},
}
function translate (v)
for i, r in pairs(translation) do -- Lookup would use floating point equality...
if vec2.dist(r, v) < 0.01 then
return i
end
end
error "unexpected vec2"
end
for _, message in ipairs(eyes) do
local values = {}
for _, a, b, c in reading.trigrams(message) do
local v = readout[a] + readout[b] + readout[c]
table.insert(values, translate(v:normalize()))
end
print(format.csv(values))
end
|