Skip to content

Instantly share code, notes, and snippets.

@odinecse
Created December 30, 2015 21:37
Show Gist options
  • Save odinecse/e729cea5ff63571ce9fb to your computer and use it in GitHub Desktop.
Save odinecse/e729cea5ff63571ce9fb to your computer and use it in GitHub Desktop.
var keyboard = [
["q", "w", "e", "r", "t", "y"],
["a", "s", "d", "f", "g", "h"],
["z", "x", "c", "v", "b", "n"]
]
var flippedX = false;
var flippedY = false;
var shifted = 0;
function flipX() {
flippedX = flippedX ? false : true;
}
function flipY() {
flippedY = flippedY ? false : true;
}
function shiftBy(i) {
shifted = i;
}
function lookup(c) {
var x = c[1];
var y = c[0];
if(shifted !== 0) {
y = (Math.floor((shifted + x)/keyboard[y].length)) % keyboard.length;
x = (shifted + x) % keyboard[y].length;
}
if(flippedY) {
y = keyboard.length - 1 - y;
}
if(flippedX) {
x = keyboard[y].length - 1 - x;
}
return [y, x];
}
function read(c) {
var ct = lookup(c);
console.log(ct);
console.log(keyboard[ct[0]][ct[1]]);
}
flipX()
read([0,0]);
flipY()
read([0,0]);
shiftBy(3)
read([0,0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment