Last active
July 5, 2022 13:21
-
-
Save burke/82ad8cf49bd96d09957f98f938004972 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/ruby --disable-gems | |
require('open3') | |
# http://fsck.com/~jesse/tmp/2019-02-15/bdfca368-6f85-40d3-ba47-e730c4c2b712/left-key-spacing.pdf | |
out, stat = Open3.capture2('qpdf', '--qdf', '--object-streams=disable', 'left-key-spacing.pdf', '-') | |
abort('qpdf fail') unless stat.success? | |
out.force_encoding(Encoding::BINARY) | |
# coordinates are indexed from top-left, x is horizontal; y is vertical | |
Point = Struct.new(:x, :y) do | |
attr_accessor(:name) | |
end | |
Line = Struct.new(:a, :b) do | |
def connected?(other) | |
a == other.a || a == other.b || b == other.a || b == other.b | |
end | |
end | |
lines = [] | |
to_millis = ->(x) { (x.to_f * 1000).to_i } | |
out.scan(/^([\d\.]+) ([\d\.]+) m ([\d\.]+) ([\d\.]+) l S Q$/m).each do |a, b, c, d| | |
x1 = to_millis.(a) | |
y1 = to_millis.(b) | |
x2 = to_millis.(c) | |
y2 = to_millis.(d) | |
p1 = Point.new(x1, y1) | |
p2 = Point.new(x2, y2) | |
lines << Line.new(p1, p2) | |
end | |
groups = [] | |
lines.each do |line| | |
next if groups.any? { |g| g.include?(line) } | |
group = lines.select { |other| line.connected?(other) } | |
group = lines.select { |other| group.any? { |gl| gl.connected?(other) } } | |
groups << group if group.size == 4 | |
end | |
abort('not enough groups') unless groups.size == 32 | |
keys = [] | |
groups.each do |group| | |
points = group.flat_map { |g| [g.a, g.b] }.uniq | |
abort('wrong # of points') unless points.size == 4 | |
x = points.map(&:x).reduce(&:+) | |
y = points.map(&:y).reduce(&:+) | |
keys << Point.new(x, y) | |
end | |
# ........................20........23........................ | |
# ................26......................12.................. | |
# ............................................................ | |
# ........00.................................................. | |
# 13......................30........11............16.......... | |
# ................19......................03.................. | |
# ............................................................ | |
# ........04.................................................. | |
# 21........................02......29........................ | |
# ..................08....................17......10.......... | |
# ............................................................ | |
# ..........22................................................ | |
# ..09......................06......14........................ | |
# ..................31....................05.................. | |
# ................................................28.......... | |
# ..07......18................................................ | |
# ............................................................ | |
# ......................................27.................... | |
# ..............................................25............ | |
# ............................................................ | |
# ....................................................15...... | |
# ............................................................ | |
# ..........................................................24 | |
# ............................................................ | |
# ............................................................ | |
# ............................................................ | |
# ............................................................ | |
# ............................................................ | |
# ............................................................ | |
# ........................................01.................. | |
# See also https://github.com/keyboardio/Kaleidoscope-MagicCombo#further-reading | |
rows_columns = [ | |
[13, 0, 26, 20, 23, 12, 16, 27], # r0 | |
[21, 4, 19, 30, 11, 3, 10, 25], # r1 | |
[9, 22, 8, 2, 29, 17, 28, 15], # r2 | |
[7, 18, 31, 6, 14, 5, 1, 24], # r3 | |
] | |
rows_columns.each.with_index do |row, r| | |
row.each.with_index do |column, c| | |
rows_columns[r][c] = keys[column] | |
end | |
end | |
# ........................03........04........................ | |
# ................02......................05.................. | |
# ............................................................ | |
# ........01.................................................. | |
# 00......................13........14............06.......... | |
# ................12......................15.................. | |
# ............................................................ | |
# ........11.................................................. | |
# 10........................23......24........................ | |
# ..................22....................25......16.......... | |
# ............................................................ | |
# ..........21................................................ | |
# ..22......................33......34........................ | |
# ..................32....................35.................. | |
# ................................................26.......... | |
# ..30......31................................................ | |
# ............................................................ | |
# ......................................07.................... | |
# ..............................................17............ | |
# ............................................................ | |
# ....................................................27...... | |
# ............................................................ | |
# ..........................................................37 | |
# ............................................................ | |
# ............................................................ | |
# ............................................................ | |
# ............................................................ | |
# ............................................................ | |
# ............................................................ | |
# ........................................36.................. | |
# max_x = 0 | |
# max_y = 0 | |
# keys.each do |key| | |
# if key.x > max_x | |
# max_x = key.x | |
# end | |
# if key.y > max_y | |
# max_y = key.y | |
# end | |
# end | |
# grid = [] | |
# X=30 | |
# Y=30 | |
# Y.times do | |
# l = [] | |
# X.times { l << ".." } | |
# grid << l | |
# end | |
# rows_columns.each.with_index do |row, r| | |
# row.each.with_index do |key, c| | |
# t_x = (key.x.to_f / max_x.to_f) * X | |
# t_y = (key.y.to_f / max_y.to_f) * Y | |
# # puts [t_x, t_y].inspect | |
# grid[t_y.to_i-1][t_x.to_i-1] = "#{r}#{c}" | |
# end | |
# end | |
# grid.each { |l| puts l.join('') } | |
max_x = 0 | |
keys.each do |key| | |
if key.x > max_x | |
max_x = key.x | |
end | |
end | |
SPACING = 400000 | |
$midpoint = max_x + (SPACING / 2.0).to_i | |
$endpoint = 2*$midpoint | |
add_mirror = ->(row) do | |
right_hand = row.reverse.map do |key| | |
key = Point.new($endpoint - key.x, key.y) | |
keys << key | |
key | |
end | |
row + right_hand | |
end | |
rows_columns.each.with_index do |row, r| | |
rows_columns[r] = add_mirror.(row) | |
end | |
# max_x = 0 | |
# max_y = 0 | |
# keys.each do |key| | |
# if key.x > max_x | |
# max_x = key.x | |
# end | |
# if key.y > max_y | |
# max_y = key.y | |
# end | |
# end | |
# grid = [] | |
# X=80 | |
# Y=30 | |
# Y.times do | |
# l = [] | |
# X.times { l << ".." } | |
# grid << l | |
# end | |
# rows_columns.each.with_index do |row, r| | |
# row.each.with_index do |key, c| | |
# t_x = (key.x.to_f / max_x.to_f) * X | |
# t_y = (key.y.to_f / max_y.to_f) * Y | |
# # puts [t_x, t_y].inspect | |
# grid[t_y.to_i-1][t_x.to_i-1] = "#{r}#{c.to_s(16)}" | |
# end | |
# end | |
# grid.each { |l| puts l.join('') } | |
# ..............................03........04..........................................................................0b........0c................................ | |
# ....................02............................05........................................................0a..........................0d...................... | |
# ................................................................................................................................................................ | |
# ..........01........................................................................................................................................0e.......... | |
# 00..............................13......14..................06....................................09................1b........1c..............................0f | |
# ......................12..........................15........................................................1a..........................1d...................... | |
# ................................................................................................................................................................ | |
# ..........11......................................................................................................................................1e............ | |
# ..10............................23......24..........................................................................2b........2c............................1f.. | |
# ......................22..........................25........16....................................19........2a..........................2d...................... | |
# ................................................................................................................................................................ | |
# ............21....................................................................................................................................2e............ | |
# ..20............................33......34..........................................................................3b........3c............................2f.. | |
# ......................32..........................35........................................................3a..........................3d...................... | |
# ............................................................26....................................29............................................................ | |
# ....30......31....................................................................................................................................3e......3f.... | |
# ................................................................................................................................................................ | |
# ................................................07............................................................08................................................ | |
# ........................................................17............................................18........................................................ | |
# ................................................................................................................................................................ | |
# ................................................................27............................28................................................................ | |
# ................................................................................................................................................................ | |
# ......................................................................37................38...................................................................... | |
# ................................................................................................................................................................ | |
# ................................................................................................................................................................ | |
# ................................................................................................................................................................ | |
# ................................................................................................................................................................ | |
# ................................................................................................................................................................ | |
# ................................................................................................................................................................ | |
# ..................................................36........................................................39.................................................. | |
DENOM = 14200 | |
max_x = 0 | |
max_y = 0 | |
keys.each do |key| | |
if key.x/DENOM > max_x | |
max_x = key.x/DENOM | |
end | |
if key.y/DENOM > max_y | |
max_y = key.y/DENOM | |
end | |
end | |
puts "static const PROGMEM uint8_t key_positions_max_x = #{max_x};" | |
puts "static const PROGMEM uint8_t key_positions_max_y = #{max_y};" | |
puts 'static const PROGMEM uint8_t key_positions[64][2] = {' | |
print(rows_columns.map.with_index do |row, r| | |
' ' + row.map.with_index do |key, c| | |
format("{%3d, %3d}", key.x/DENOM, key.y/DENOM) | |
end.join(', ') | |
end.join(",\n")) | |
puts "\n};" | |
puts 'static const PROGMEM uint8_t key_distances[4096] = {' | |
def dist(x1, y1, x2, y2) | |
Math.sqrt((x2-x1)**2 + (y2-y1)**2).to_i | |
end | |
distances = [] | |
64.times { distances << [] } | |
rows_columns.each.with_index do |row, r| | |
row.each.with_index do |key, c| | |
x1 = key.x/DENOM | |
y1 = key.y/DENOM | |
rows_columns.each.with_index do |row2, r2| | |
row2.each.with_index do |key2, c2| | |
x2 = key2.x/DENOM | |
y2 = key2.y/DENOM | |
distances[r*16+c][r2*16+c2] = dist(x1,y1,x2,y2) | |
end | |
end | |
end | |
end | |
print(distances.map.with_index do |row, r| | |
row.map.with_index do |dist, c| | |
dist.to_s | |
end.join(',') | |
end.join(",\n")) | |
puts "\n};" | |
# static const PROGMEM uint8_t key_positions_max_x = 255; | |
# static const PROGMEM uint8_t key_positions_max_y = 110; | |
# static const PROGMEM uint8_t key_positions[64][2] = { | |
# { 5, 19}, { 20, 18}, { 38, 9}, { 54, 5}, { 70, 6}, { 85, 9}, {100, 20}, { 80, 69}, {180, 69}, {160, 20}, {175, 9}, {191, 6}, {207, 5}, {223, 9}, {240, 18}, {255, 19}, | |
# { 7, 33}, { 22, 32}, { 38, 23}, { 54, 19}, { 70, 20}, { 85, 23}, {100, 38}, { 93, 73}, {167, 73}, {160, 38}, {175, 23}, {191, 20}, {207, 19}, {222, 23}, {239, 32}, {254, 33}, | |
# { 8, 48}, { 23, 46}, { 39, 38}, { 54, 34}, { 70, 34}, { 85, 38}, {100, 56}, {105, 80}, {155, 80}, {160, 56}, {175, 38}, {191, 34}, {206, 34}, {222, 38}, {237, 46}, {252, 48}, | |
# { 9, 62}, { 24, 61}, { 39, 52}, { 54, 48}, { 70, 49}, { 85, 52}, { 85, 110}, {116, 88}, {144, 88}, {175, 110}, {175, 52}, {191, 49}, {206, 48}, {221, 52}, {236, 61}, {251, 62} | |
# }; | |
# static const PROGMEM uint8_t key_distances[4096] = { | |
# 0,15,34,50,66,80,95,90,182,155,170,186,202,218,235,250,14,21,33,49,65,80,96,103,170,156,170,186,202,217,234,249,29,32,38,51,66,82,101,117,161,159,171,186,201,217,233,248,43,46,47,56,71,86,121,130,155,192,173,188,203,218,234,249, | |
# 15,0,20,36,51,65,80,78,167,140,155,171,187,203,220,235,19,14,18,34,50,65,82,91,156,141,155,171,187,202,219,234,32,28,27,37,52,68,88,105,148,145,156,171,186,202,218,233,45,43,38,45,58,73,112,118,142,180,158,173,188,203,220,235, | |
# 34,20,0,16,32,47,62,73,154,122,137,153,169,185,202,217,39,28,14,18,33,49,68,84,144,125,137,153,169,184,202,217,49,39,29,29,40,55,77,97,136,130,140,155,169,186,202,217,60,53,43,42,51,63,111,111,132,170,143,158,172,187,204,219, | |
# 50,36,16,0,16,31,48,69,141,107,121,137,153,169,186,201,54,41,24,14,21,35,56,78,131,111,122,137,153,168,186,201,62,51,36,29,33,45,68,90,125,117,125,140,154,171,187,202,72,63,49,43,46,56,109,103,122,160,129,143,157,173,190,205, | |
# 66,51,32,16,0,15,33,63,126,91,105,121,137,153,170,185,68,54,36,20,14,22,43,70,117,95,106,121,137,152,170,185,74,61,44,32,28,35,58,81,112,102,109,124,138,155,171,186,82,71,55,44,43,48,105,94,110,147,114,128,142,157,174,189, | |
# 80,65,47,31,15,0,18,60,112,75,90,106,122,138,155,170,81,67,49,32,18,14,32,64,104,80,91,106,122,137,155,170,86,72,54,39,29,29,49,73,99,88,94,108,123,140,156,171,92,80,62,49,42,43,101,84,98,135,99,113,127,142,159,174, | |
# 95,80,62,48,33,18,0,52,93,60,75,92,108,123,140,155,93,78,62,46,30,15,18,53,85,62,75,91,107,122,139,154,96,81,63,48,33,23,36,60,81,69,77,92,106,123,139,154,100,86,68,53,41,35,91,69,80,117,81,95,109,125,142,156, | |
# 90,78,73,69,63,60,52,0,100,93,112,127,142,155,167,182,81,68,62,56,50,46,36,13,87,85,105,121,136,149,163,177,75,61,51,43,36,31,23,27,75,81,99,116,130,145,158,173,71,56,44,33,22,17,41,40,66,103,96,112,127,142,156,171, | |
# 182,167,154,141,126,112,93,100,0,52,60,63,69,73,78,90,176,162,149,135,120,105,85,87,13,36,46,50,56,62,69,82,173,158,144,130,115,99,81,75,27,23,31,36,43,52,61,75,171,156,142,127,111,96,103,66,40,41,17,22,33,44,56,71, | |
# 155,140,122,107,91,75,60,93,52,0,18,34,49,63,80,95,153,138,122,106,90,75,62,85,53,18,15,31,47,62,79,94,154,139,122,106,91,77,69,81,60,36,23,34,48,64,81,96,156,142,125,109,94,81,117,80,69,91,35,42,53,68,86,100, | |
# 170,155,137,121,105,90,75,112,60,18,0,16,32,48,65,80,169,154,137,121,105,91,80,104,64,32,14,19,33,49,68,82,171,156,139,123,107,94,88,99,73,49,29,29,39,55,72,86,174,159,142,127,112,99,135,98,84,101,43,43,49,62,80,92, | |
# 186,171,153,137,121,106,92,127,63,34,16,0,16,32,50,65,185,170,153,137,121,107,96,118,71,44,23,14,20,35,54,68,187,172,155,139,124,110,103,113,82,58,35,28,31,44,60,74,190,175,158,143,128,115,148,111,94,105,48,43,44,54,71,82, | |
# 202,187,169,153,137,122,108,142,69,49,32,16,0,16,35,50,201,186,169,153,137,123,111,132,78,57,36,21,14,23,41,54,203,188,171,155,140,126,118,126,91,69,45,33,29,36,50,62,206,191,174,158,143,130,160,123,104,109,56,46,43,49,63,72, | |
# 218,203,185,169,153,138,123,155,73,63,48,32,16,0,19,33,217,202,185,169,153,138,126,144,85,69,50,33,18,14,28,39,218,203,186,170,155,141,131,137,98,78,56,40,30,29,39,48,220,205,188,173,158,144,171,133,111,111,64,51,42,43,53,59, | |
# 235,220,202,186,170,155,140,167,78,80,65,50,35,19,0,15,233,218,202,186,170,155,141,156,91,82,65,49,33,18,14,20,233,218,201,186,170,156,145,148,105,88,68,51,37,26,28,32,235,220,203,188,172,158,180,142,118,112,73,57,45,38,43,45, | |
# 250,235,217,201,185,170,155,182,90,95,80,65,50,33,15,0,248,233,217,201,185,170,156,170,103,96,80,64,48,33,20,14,248,233,216,201,185,171,159,161,117,101,82,65,51,38,32,29,249,234,218,203,187,173,192,155,130,121,86,70,56,47,46,43, | |
# 14,19,39,54,68,81,93,81,176,153,169,185,201,217,233,248,0,15,32,49,64,78,93,94,164,153,168,184,200,215,232,247,15,20,32,47,63,78,95,108,155,154,168,184,199,215,230,245,29,32,37,49,65,80,109,122,147,184,169,184,199,214,230,245, | |
# 21,14,28,41,54,67,78,68,162,138,154,170,186,202,218,233,15,0,18,34,49,63,78,81,150,138,153,169,185,200,217,232,21,14,18,32,48,63,81,95,141,140,153,169,184,200,215,230,32,29,26,35,50,66,100,109,134,171,154,169,184,200,215,230, | |
# 33,18,14,24,36,49,62,62,149,122,137,153,169,185,202,217,32,18,0,16,32,47,63,74,138,122,137,153,169,184,201,216,39,27,15,19,33,49,70,87,130,126,137,153,168,184,200,215,48,40,29,29,41,55,98,101,124,162,140,155,169,185,201,216, | |
# 49,34,18,14,20,32,46,56,135,106,121,137,153,169,186,201,49,34,16,0,16,31,49,66,125,107,121,137,153,168,185,200,54,41,24,15,21,36,59,79,117,112,122,137,152,169,184,200,62,51,36,29,34,45,96,92,113,151,125,140,154,170,186,201, | |
# 65,50,33,21,14,18,30,50,120,90,105,121,137,153,170,185,64,49,32,16,0,15,34,57,110,91,105,121,137,152,169,184,68,53,35,21,14,23,46,69,104,96,106,121,136,153,169,184,74,61,44,32,29,35,91,82,100,138,109,124,138,154,170,185, | |
# 80,65,49,35,22,14,15,46,105,75,91,107,123,138,155,170,78,63,47,31,15,0,21,50,96,76,90,106,122,137,154,169,80,66,48,32,18,15,36,60,90,81,91,106,121,137,153,168,85,71,54,39,30,29,87,72,87,125,94,109,123,139,155,170, | |
# 96,82,68,56,43,32,18,36,85,62,80,96,111,126,141,156,93,78,63,49,34,21,0,35,75,60,76,92,108,122,139,154,92,77,61,46,30,15,18,42,69,62,75,91,106,122,137,152,94,79,62,47,31,20,73,52,66,103,76,91,106,121,137,152, | |
# 103,91,84,78,70,64,53,13,87,85,104,118,132,144,156,170,94,81,74,66,57,50,35,0,74,75,96,111,126,138,151,165,88,75,64,55,45,35,18,13,62,69,89,105,119,133,146,160,84,70,57,46,33,22,37,27,53,89,84,100,115,129,143,158, | |
# 170,156,144,131,117,104,85,87,13,53,64,71,78,85,91,103,164,150,138,125,110,96,75,74,0,35,50,58,67,74,82,95,160,146,132,119,104,89,69,62,13,18,35,45,55,65,75,88,158,143,129,115,99,84,89,53,27,37,22,33,46,57,70,84, | |
# 156,141,125,111,95,80,62,85,36,18,32,44,57,69,82,96,153,138,122,107,91,76,60,75,35,0,21,35,50,63,79,94,152,137,121,106,90,75,62,69,42,18,15,31,46,62,77,92,152,137,121,106,90,76,103,66,52,73,20,32,47,62,79,94, | |
# 170,155,137,122,106,91,75,105,46,15,14,23,36,50,65,80,168,153,137,121,105,90,76,96,50,21,0,16,32,47,64,79,168,153,136,121,105,91,81,90,60,36,15,19,32,49,66,80,170,155,139,123,108,94,125,87,72,87,29,30,39,54,71,85, | |
# 186,171,153,137,121,106,91,121,50,31,19,14,21,33,49,64,184,169,153,137,121,106,92,111,58,35,16,0,16,31,49,64,185,170,153,137,121,107,97,104,69,47,24,14,20,35,52,67,186,171,155,139,124,110,139,101,82,91,35,29,31,43,60,73, | |
# 202,187,169,153,137,122,107,136,56,47,33,20,14,18,33,48,200,185,169,153,137,122,108,126,67,50,32,16,0,15,34,49,201,185,169,153,137,123,113,118,80,59,37,21,15,24,40,53,202,187,171,155,140,126,152,114,93,96,45,34,29,35,51,61, | |
# 217,202,184,168,152,137,122,149,62,62,49,35,23,14,18,33,215,200,184,168,152,137,122,138,74,63,47,31,15,0,19,33,215,200,183,168,152,137,126,130,87,70,49,32,19,15,27,39,216,201,185,169,154,140,162,124,101,98,55,40,29,29,40,48, | |
# 234,219,202,186,170,155,139,163,69,79,68,54,41,28,14,20,232,217,201,185,169,154,139,151,82,79,64,49,34,19,0,15,231,216,200,185,169,154,141,142,96,82,64,48,33,18,14,20,231,216,200,185,169,155,172,135,110,100,67,50,36,26,29,32, | |
# 249,234,217,201,185,170,154,177,82,94,82,68,54,39,20,14,247,232,216,200,184,169,154,165,95,94,79,64,49,33,15,0,246,231,215,200,184,169,155,156,109,96,79,63,48,32,21,15,246,231,215,200,184,170,185,148,122,110,81,65,50,38,33,29, | |
# 29,32,49,62,74,86,96,75,173,154,171,187,203,218,233,248,15,21,39,54,68,80,92,88,160,152,168,185,201,215,231,246,0,15,32,48,63,77,92,102,150,152,167,183,198,214,229,244,14,20,31,46,62,77,98,115,141,178,167,183,198,213,228,243, | |
# 32,28,39,51,61,72,81,61,158,139,156,172,188,203,218,233,20,14,27,41,53,66,77,75,146,137,153,170,185,200,216,231,15,0,17,33,48,62,77,88,136,137,152,168,183,199,214,229,21,15,17,31,47,62,89,102,128,164,152,168,183,198,213,228, | |
# 38,27,29,36,44,54,63,51,144,122,139,155,171,186,201,216,32,18,15,24,35,48,61,64,132,121,136,153,169,183,200,215,32,17,0,15,31,46,63,78,123,122,136,152,167,183,198,213,38,27,14,18,32,48,85,91,116,153,136,152,167,182,198,213, | |
# 51,37,29,29,32,39,48,43,130,106,123,139,155,170,186,201,47,32,19,15,21,32,46,55,119,106,121,137,153,168,185,200,48,33,15,0,16,31,50,68,110,108,121,137,152,168,183,198,53,40,23,14,21,35,82,82,104,142,122,137,152,167,183,198, | |
# 66,52,40,33,28,29,33,36,115,91,107,124,140,155,170,185,63,48,33,21,14,18,30,45,104,90,105,121,137,152,169,184,63,48,31,16,0,15,37,57,96,92,105,121,136,152,167,182,67,53,35,21,15,23,77,70,91,129,106,121,136,152,168,183, | |
# 82,68,55,45,35,29,23,31,99,77,94,110,126,141,156,171,78,63,49,36,23,15,15,35,89,75,91,107,123,137,154,169,77,62,46,31,15,0,23,46,81,77,90,106,121,137,152,167,79,65,48,32,18,14,72,58,77,115,91,106,121,136,152,167, | |
# 101,88,77,68,58,49,36,23,81,69,88,103,118,131,145,159,95,81,70,59,46,36,18,18,69,62,81,97,113,126,141,155,92,77,63,50,37,23,0,24,60,60,77,93,108,123,137,152,91,76,61,46,30,15,56,35,54,92,75,91,106,121,136,151, | |
# 117,105,97,90,81,73,60,27,75,81,99,113,126,137,148,161,108,95,87,79,69,60,42,13,62,69,90,104,118,130,142,156,102,88,78,68,57,46,24,0,50,60,81,97,110,124,136,150,97,83,71,60,46,34,36,13,39,76,75,91,105,119,132,147, | |
# 161,148,136,125,112,99,81,75,27,60,73,82,91,98,105,117,155,141,130,117,104,90,69,62,13,42,60,69,80,87,96,109,150,136,123,110,96,81,60,50,0,24,46,58,68,79,88,102,147,132,119,105,90,75,76,39,13,36,34,47,60,71,83,97, | |
# 159,145,130,117,102,88,69,81,23,36,49,58,69,78,88,101,154,140,126,112,96,81,62,69,18,18,36,47,59,70,82,96,152,137,122,108,92,77,60,60,24,0,23,38,50,64,77,92,151,136,121,106,90,75,92,54,35,56,15,31,46,61,76,91, | |
# 171,156,140,125,109,94,77,99,31,23,29,35,45,56,68,82,168,153,137,122,106,91,75,89,35,15,15,24,37,49,64,79,167,152,136,121,105,90,77,81,46,23,0,16,31,47,62,77,167,152,136,121,105,91,115,77,58,72,14,19,32,48,65,79, | |
# 186,171,155,140,124,108,92,116,36,34,29,28,33,40,51,65,184,169,153,137,121,106,91,105,45,31,19,14,21,32,48,63,183,168,152,137,121,106,93,97,58,38,16,0,15,31,47,62,184,169,153,137,121,107,130,92,71,77,24,15,20,34,52,66, | |
# 201,186,169,154,138,123,106,130,43,48,39,31,29,30,37,51,199,184,168,152,136,121,106,119,55,46,32,20,15,19,33,48,198,183,167,152,136,121,108,110,68,50,31,15,0,16,33,48,198,183,167,152,136,122,142,104,82,82,35,21,14,23,40,53, | |
# 217,202,186,171,155,140,123,145,52,64,55,44,36,29,26,38,215,200,184,169,153,137,122,133,65,62,49,35,24,15,18,32,214,199,183,168,152,137,123,124,79,64,47,31,16,0,17,31,214,199,183,168,152,137,154,117,92,85,49,32,18,14,26,37, | |
# 233,218,202,187,171,156,139,158,61,81,72,60,50,39,28,32,230,215,200,184,169,153,137,146,75,77,66,52,40,27,14,21,229,214,198,183,167,152,137,136,88,77,62,47,33,17,0,15,228,213,198,183,167,152,164,128,102,89,62,46,31,17,15,21, | |
# 248,233,217,202,186,171,154,173,75,96,86,74,62,48,32,29,245,230,215,200,184,168,152,160,88,92,80,67,53,39,20,15,244,229,213,198,182,167,152,150,102,92,77,62,48,31,15,0,243,228,213,198,182,167,178,141,115,98,77,61,46,31,20,14, | |
# 43,45,60,72,82,92,100,71,171,156,174,190,206,220,235,249,29,32,48,62,74,85,94,84,158,152,170,186,202,216,231,246,14,21,38,53,67,79,91,97,147,151,167,184,198,214,228,243,0,15,31,47,62,76,89,110,137,172,166,182,197,212,227,242, | |
# 46,43,53,63,71,80,86,56,156,142,159,175,191,205,220,234,32,29,40,51,61,71,79,70,143,137,155,171,187,201,216,231,20,15,27,40,53,65,76,83,132,136,152,169,183,199,213,228,15,0,17,32,47,61,78,95,123,158,151,167,182,197,212,227, | |
# 47,38,43,49,55,62,68,44,142,125,142,158,174,188,203,218,37,26,29,36,44,54,62,57,129,121,139,155,171,185,200,215,31,17,14,23,35,48,61,71,119,121,136,153,167,183,198,213,31,17,0,15,31,46,74,85,111,147,136,152,167,182,197,212, | |
# 56,45,42,43,44,49,53,33,127,109,127,143,158,173,188,203,49,35,29,29,32,39,47,46,115,106,123,139,155,169,185,200,46,31,18,14,21,32,46,60,105,106,121,137,152,168,183,198,47,32,15,0,16,31,69,73,98,135,121,137,152,167,182,197, | |
# 71,58,51,46,43,42,41,22,111,94,112,128,143,158,172,187,65,50,41,34,29,30,31,33,99,90,108,124,140,154,169,184,62,47,32,21,15,18,30,46,90,90,105,121,136,152,167,182,62,47,31,16,0,15,62,60,83,121,105,121,136,151,166,181, | |
# 86,73,63,56,48,43,35,17,96,81,99,115,130,144,158,173,80,66,55,45,35,29,20,22,84,76,94,110,126,140,155,170,77,62,48,35,23,14,15,34,75,75,91,107,122,137,152,167,76,61,46,31,15,0,58,47,69,107,90,106,121,136,151,166, | |
# 121,112,111,109,105,101,91,41,103,117,135,148,160,171,180,192,109,100,98,96,91,87,73,37,89,103,125,139,152,162,172,185,98,89,85,82,77,72,56,36,76,92,115,130,142,154,164,178,89,78,74,69,62,58,0,38,62,90,107,122,135,147,158,172, | |
# 130,118,111,103,94,84,69,40,66,80,98,111,123,133,142,155,122,109,101,92,82,72,52,27,53,66,87,101,114,124,135,148,115,102,91,82,70,58,35,13,39,54,77,92,104,117,128,141,110,95,85,73,60,47,38,0,28,62,69,84,98,111,123,137, | |
# 155,142,132,122,110,98,80,66,40,69,84,94,104,111,118,130,147,134,124,113,100,87,66,53,27,52,72,82,93,101,110,122,141,128,116,104,91,77,54,39,13,35,58,71,82,92,102,115,137,123,111,98,83,69,62,28,0,38,47,61,73,85,95,110, | |
# 192,180,170,160,147,135,117,103,41,91,101,105,109,111,112,121,184,171,162,151,138,125,103,89,37,73,87,91,96,98,100,110,178,164,153,142,129,115,92,76,36,56,72,77,82,85,89,98,172,158,147,135,121,107,90,62,38,0,58,63,69,74,78,89, | |
# 173,158,143,129,114,99,81,96,17,35,43,48,56,64,73,86,169,154,140,125,109,94,76,84,22,20,29,35,45,55,67,81,167,152,136,122,106,91,75,75,34,15,14,24,35,49,62,77,166,151,136,121,105,90,107,69,47,58,0,16,31,46,61,76, | |
# 188,173,158,143,128,113,95,112,22,42,43,43,46,51,57,70,184,169,155,140,124,109,91,100,33,32,30,29,34,40,50,65,183,168,152,137,121,106,91,91,47,31,19,15,21,32,46,61,182,167,152,137,121,106,122,84,61,63,16,0,15,30,46,61, | |
# 203,188,172,157,142,127,109,127,33,53,49,44,43,42,45,56,199,184,169,154,138,123,106,115,46,47,39,31,29,29,36,50,198,183,167,152,136,121,106,105,60,46,32,20,14,18,31,46,197,182,167,152,136,121,135,98,73,69,31,15,0,15,32,47, | |
# 218,203,187,173,157,142,125,142,44,68,62,54,49,43,38,47,214,200,185,170,154,139,121,129,57,62,54,43,35,29,26,38,213,198,182,167,152,136,121,119,71,61,48,34,23,14,17,31,212,197,182,167,151,136,147,111,85,74,46,30,15,0,17,31, | |
# 234,220,204,190,174,159,142,156,56,86,80,71,63,53,43,46,230,215,201,186,170,155,137,143,70,79,71,60,51,40,29,33,228,213,198,183,168,152,136,132,83,76,65,52,40,26,15,20,227,212,197,182,166,151,158,123,95,78,61,46,32,17,0,15, | |
# 249,235,219,205,189,174,156,171,71,100,92,82,72,59,45,43,245,230,216,201,185,170,152,158,84,94,85,73,61,48,32,29,243,228,213,198,183,167,151,147,97,91,79,66,53,37,21,14,242,227,212,197,181,166,172,137,110,89,76,61,47,31,15,0 | |
# }; | |
# ..............................32........42..........................................................................ba........ca................................ | |
# ....................22............................50........................................................aa..........................da...................... | |
# ................................................................................................................................................................ | |
# ..........0f........................................................................................................................................eb.......... | |
# 00..............................31......41..................5f....................................9b................ba........ca..............................fa | |
# ......................21..........................50........................................................aa..........................d9...................... | |
# ................................................................................................................................................................ | |
# ..........15......................................................................................................................................ea............ | |
# ..0e............................33......42..........................................................................ba........c9............................f9.. | |
# ......................26..........................52........60....................................9c........ab..........................d9...................... | |
# ................................................................................................................................................................ | |
# ............20....................................................................................................................................e9............ | |
# ..1d............................38......47..........................................................................bc........cb............................f8.. | |
# ......................2f..........................56........................................................ad..........................da...................... | |
# ............................................................65....................................9f............................................................ | |
# ....2b......2e....................................................................................................................................ea......f9.... | |
# ................................................................................................................................................................ | |
# ................................................5a............................................................b6................................................ | |
# ........................................................67............................................aa........................................................ | |
# ................................................................................................................................................................ | |
# ................................................................75............................a1................................................................ | |
# ................................................................................................................................................................ | |
# ......................................................................82................9b...................................................................... | |
# ................................................................................................................................................................ | |
# ................................................................................................................................................................ | |
# ................................................................................................................................................................ | |
# ................................................................................................................................................................ | |
# ................................................................................................................................................................ | |
# ................................................................................................................................................................ | |
# ..................................................79........................................................c0.................................................. | |
max_x = 0 | |
max_y = 0 | |
keys.each do |key| | |
if key.x > max_x | |
max_x = key.x | |
end | |
if key.y > max_y | |
max_y = key.y | |
end | |
end | |
grid = [] | |
X=80 | |
Y=30 | |
Y.times do | |
l = [] | |
X.times { l << ".." } | |
grid << l | |
end | |
rows_columns.each.with_index do |row, r| | |
row.each.with_index do |key, c| | |
t_x = (key.x.to_f / max_x.to_f) * X | |
t_y = (key.y.to_f / max_y.to_f) * Y | |
# puts [t_x, t_y].inspect | |
grid[t_y.to_i-1][t_x.to_i-1] = format("%02x", distances[0][r*16+c]) | |
end | |
end | |
grid.each { |l| puts l.join('') } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment