Last active
August 29, 2015 13:57
-
-
Save skratchdot/9793552 to your computer and use it in GitHub Desktop.
patatap.com random keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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