Skip to content

Instantly share code, notes, and snippets.

@skratchdot
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save skratchdot/9793552 to your computer and use it in GitHub Desktop.

Select an option

Save skratchdot/9793552 to your computer and use it in GitHub Desktop.
patatap.com random keys
/*
visit http://www.patatap.com/ then run this code in your
console. change the bpm and maxNotes variables
*/
(function (global) {
var bpm = 80,
maxNotes = 5,
interval = (60 * 1000) / bpm,
between = function (min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
};
// clear any previously set intervals (idempotence)
clearInterval(global.NOTE_INTERVAL);
// hit some random keys on an interval
global.NOTE_INTERVAL = setInterval(function () {
var i, key, notes = between(0, maxNotes);
console.clear();
console.log('playing:');
for (i = 0; i < notes; i++) {
key = between(65, 90);
console.log(key, ':', String.fromCharCode(key));
jQuery.event.trigger({
type: 'keydown',
which: key
});
}
}, interval);
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment