Skip to content

Instantly share code, notes, and snippets.

@David256
Created April 17, 2021 17:49
Show Gist options
  • Save David256/7bd94438dc460ff14e93f6c77b3f76d4 to your computer and use it in GitHub Desktop.
Save David256/7bd94438dc460ff14e93f6c77b3f76d4 to your computer and use it in GitHub Desktop.
I don't know why
const L = 37, R = 39, U = 38, D = 40;
let a = [
[L, U, R, D], [L, D, R, U],
[R, U, L, D], [R, D, L, U],
[U, L, D, R], [U, R, D, L],
[D, L, U, R], [D, R, U, L]
];
let d = document;
let c = d.getElementsByTagName("canvas")[0];
let gdir = () => { return a[Math.floor(Math.random() * a.length)]; }
let sim = (co,t) => {
let eA = d.createEvent("HTMLEvents");
let eB = d.createEvent("HTMLEvents");
eA.initEvent("keydown", true, true);
eB.initEvent("keyup", true, true);
eA.keyCode = co;
eB.keyCode = co;
c.dispatchEvent(eA);
console.log(co, "down");
setTimeout(() => { c.dispatchEvent(eB); console.log(co, "up") }, t);
};
let floop = () => {
let dir = gdir();
setTimeout(sim, 0, dir[0], 2000);
setTimeout(sim, 2000, dir[1], 2000);
setTimeout(sim, 4000, dir[2], 2000);
setTimeout(sim, 6000, dir[3], 2000);
setTimeout(floop, 8000);
};
floop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment