Skip to content

Instantly share code, notes, and snippets.

@rorhug
Created August 24, 2014 08:39
Show Gist options
  • Save rorhug/7d90afb5893525e9f0fa to your computer and use it in GitHub Desktop.
Save rorhug/7d90afb5893525e9f0fa to your computer and use it in GitHub Desktop.
Bayan music
// SETTINGS
var input = "rsa ecde srgu yhgr bv rsa ecde srgu yhgr bv hybtg ser erv";
input += " hybtg iii r hybtg ser erv tvr rrr rvgres rrr rvg rrr rvgres ";
input += "ggg rgh grs sxebbe cuuuhbgres grs sxebbe cbbbgvrsai";
var TIME_INTERVAL = 300;
// Add jquery
var script = document.createElement('script');
script.src = 'http://code.jquery.com/jquery-1.11.0.min.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
function play () {
// Sound array setup
var soundArray = [];
var down = $.Event("keydown");
var up = $.Event("keyup");
input = ' ' + input; // hack
for (var i = 0; i < input.length; ++i) {
soundArray.push(input.toUpperCase().charCodeAt(i));
}
// Start sound
var index = 0;
function playSound () {
up.which = soundArray[index];
$("body").trigger(up);
++index;
down.which = soundArray[index];
$("body").trigger(down);
// // is there another?
if (index < soundArray.length) {
setTimeout(playSound, TIME_INTERVAL);
}
}
playSound();
}
(function loadjQuery () {
if (typeof jQuery === 'undefined') {
setTimeout(loadjQuery, 100);
} else {
play();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment