left4me/experiments/keyboard/keyboard.rb
mwiegand ed563d9a19
wip
2022-11-19 19:07:09 +01:00

85 lines
2.4 KiB
Ruby
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env ruby
require "erb"
keycaps = {
'h1': {
width: 1,
points: '-0.44,-0.44 0.44,-0.44 0.44,0.44 -0.44,0.44',
},
'h1.25': {
width: 1.25,
points: '-0.565,-0.44 0.565,-0.44 0.565,0.44 -0.565,0.44',
},
'h1.5': {
width: 1.5,
points: '-0.69,-0.44 0.69,-0.44 0.69,0.44 -0.69,0.44',
},
'h1.75': {
width: 1.75,
points: '-0.815,-0.44 0.815,-0.44 0.815,0.44 -0.815,0.44',
},
'h2': {
width: 2,
points: '-0.94,-0.44 0.94,-0.44 0.94,0.44 -0.94,0.44',
},
'h2.5': {
width: 2.5,
points: '-1.19,-0.44 1.19,-0.44 1.19,0.44 -1.19,0.44',
},
'h2.75': {
width: 2.75,
points: '-1.315,-0.44 1.315,-0.44 1.315,0.44 -1.315,0.44',
},
'h6.5': {
width: 6.5,
points: '-3.19,-0.44 3.19,-0.44 3.19,0.44 -3.19,0.44',
},
'v2': {
width: 1,
points: '-0.44,-0.44 0.44,-0.44 0.44,1.44 -0.44,1.44',
},
'enter_iso': {
width: 1.5,
points: '-0.69,-0.44 0.69,-0.44 0.69,1.44 -0.44,1.44 -0.44,0.44 -0.69,0.44',
},
}
keyboard = {
0 => 'ESC :1 F1 F2 F3 F4 :.5 F5 F6 F7 F8 :.5 F9 F10 F11 F12 :.25 PNT ROL PAU',
1.75 => '^ 1 2 3 4 5 6 7 8 9 0 ß ´ BACKSP:h2 :.25 INS HOM PUP :.25 NUM / * -',
2.75 => 'TAB:h1.5 Q W E R T Z U I O P Ü + ENT:enter_iso :.25 DEL END PDN :.25 7 8 9 +:v2',
3.75 => 'CAPS:h1.75 A S D F G H J K L Ö Ä # :1.25 :.25 :1 :1 :1 :.25 4 5 6',
4.75 => 'SHIFT:h1.25 < Y X C V B N M , . - SHIFT:h2.75 :.25 :1 ARU :1 :.25 1 2 3 ENT:v2',
5.75 => 'CTL:h1.25 SUP:h1.25 ALT:h1.25 SPACE:h6.5 AGR:h1.25 SUP:h1.25 MENU CTL:h1.25 :.25 ARL ARD ARR :.25 0:h2 DEL'
}
keys = []
total_h = 0
total_v = 0
keyboard.each do |row_v, row_text|
row_h = 0
row_text.split.each do |element|
if element.start_with? ':'
row_h += element[1..].to_f
else
key, keycap = element.split(':')
keycap ||= :h1
keys.append({
name: key,
keycap: keycap,
x: row_h + keycaps[keycap.to_sym][:width]/2.0,
y: 0.5 + row_v,
})
row_h += keycaps[keycap.to_sym][:width]
end
end
total_h = [total_h, row_h].max
total_v = [total_v, row_v].max
end
p keys
html = ERB.new(File.read(File.join(__dir__, 'keyboard.erb'))).result(binding)
File.write(File.join(__dir__, 'keyboard.html'), html)