Created
June 16, 2015 06:08
-
-
Save mdavey/5a190a40ea399ddf6226 to your computer and use it in GitHub Desktop.
Code to generate SVG layout for a KBT Pure Pro Keyboard
This file contains 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
--noescape-- | |
local tag = doku.xml_tag | |
local unit = 19*2 -- Unit size, mapped straight to pixels | |
local space = 4 -- Spacing between keys (as pixels again) | |
local halfspace = space/2 | |
local doublespace = space*2 | |
local fontsize = 10 | |
local layout = { | |
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, | |
{1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5}, | |
{1.75, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2.25}, | |
{2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, | |
{1.25, 1, 1, 1.25, 4.5, 1, 1, 1, 1, 1, 1} | |
} | |
local keys = { | |
{'esc', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\\', 'BS'}, | |
{'tab', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 'del'}, | |
{'caps', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k',' l', ';', '\'', 'enter'}, | |
{'shift', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 'shift', 'up', 'rctrl'}, | |
{'lctrl', 'fn', 'sys', 'lalt', 'space', 'ralt', 'fn', 'pn', 'left', 'down', 'right'}, | |
} | |
local scene = {} | |
local background = tag('rect', {width="100%", height="100%", fill="#ddd", stroke="black"}) | |
table.insert(scene, background) | |
for row=1, #layout do | |
x = unit | |
for col=1, #layout[row] do | |
local rect = tag('rect', {x=x+halfspace, | |
y=(row*unit)+halfspace, | |
rx=halfspace, | |
ry=halfspace, | |
width=(layout[row][col]*unit)-space, | |
height=unit-space, | |
fill="#fff", | |
stroke="black"}) | |
table.insert(scene, rect) | |
local sizetext = tag('text', {x=x+doublespace, | |
y=((row)*unit)+space+fontsize, | |
fill="#d11", | |
style='font-size: ' .. fontsize .. 'px'}, | |
tostring(layout[row][col])) | |
table.insert(scene, sizetext) | |
if keys[row] and keys[row][col] then | |
local keytext = tag('text', {x=x+doublespace, | |
y=((row)*unit)+(2*fontsize)+(3*space), | |
fill="#111", | |
style='font-size: ' .. fontsize .. 'px'}, | |
keys[row][col]) | |
table.insert(scene, keytext) | |
end | |
x = x + (layout[row][col]*unit) | |
end | |
end | |
-- Keyboard is 15 units by 5 units (+1 each side for padding) | |
print(tag('svg', {width=(unit*17), height=(unit*7)}, scene)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment