Skip to content

Instantly share code, notes, and snippets.

@BrainBuzzer
Created February 7, 2022 10:39
Show Gist options
  • Save BrainBuzzer/4ea533cad48bb6b84a28890f4aadb57a to your computer and use it in GitHub Desktop.
Save BrainBuzzer/4ea533cad48bb6b84a28890f4aadb57a to your computer and use it in GitHub Desktop.
I swear it's not complete. It's made in 15 minutes. If you want, copy paste the code in console of any profile on GitHub.
let el = document.getElementsByClassName('js-calendar-graph-svg')[0].children[0]
let interval = null;
let refreshInterval = 200;
let directionVectors = {
37: {x: -1, y: 0},
38: {x: 0, y: -1},
39: {x: 1, y: 0},
40: {x: 0, y: 1}
}
let initialPosition = [20, 0]
let currentVector = {x: 1, y: 0}
document.addEventListener('keydown', function(e) {
if(e.keyCode === 37 || e.keyCode === 38 || e.keyCode === 39 || e.keyCode === 40) {
e.preventDefault();
currentVector = directionVectors[e.keyCode];
clearInterval(interval)
interval = setInterval(move, refreshInterval)
}
})
function move() {
clearPreviousHead()
initialPosition[0] += currentVector.x;
initialPosition[1] += currentVector.y;
setSnakeHeadPosition(initialPosition[0], initialPosition[1])
}
function clearPreviousHead() {
el.children[initialPosition[0]].children[initialPosition[1]].style = ""
}
function setSnakeHeadPosition(x, y) {
el.children[x].children[y].style = "fill: red";
el.children[x].children[y].dataset["level"] = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment