Public
Edited
Dec 2, 2020
Insert cell
Insert cell
Insert cell
Insert cell
Generators.observe(change => {
const axesBtns = gp => `${gp.axes.length} axes/${gp.buttons.length} buttons`;
const info = gp => `Gamepad #${gp.index} "${gp.id}" [${axesBtns(gp)}]`;
const formatGamepads = gamepads => gamepads.map(info).join('\n');
setInterval(() => change(formatGamepads(getGamepads())), 500);
})
Insert cell
Insert cell
Generators.observe(change => {
const buttons = gp => gp.buttons.map(b => (b.pressed ? 'O' : '.')).join('');
const axeSign = a => '-.+'[Math.sign(Math.round(a)) + 1];
const axes = gp => gp.axes.map(axeSign).join('');
const info = gp => `Gamepad #${gp.index}: ${axes(gp)} ${buttons(gp)}`;
const formatGamepads = gamepads => gamepads.map(info).join('\n');
setInterval(() => change(formatGamepads(getGamepads())), 100);
})
Insert cell
getGamepads = () => [...navigator.getGamepads()].filter(g => g);
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more