This file contains 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
function makeRequest(method, url) { | |
return new Promise(function(resolve, reject) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open(method, url); | |
xhr.onload = function() { | |
if (this.status >= 200 && this.status < 300) { | |
resolve(xhr.response); | |
} else { | |
reject({ | |
status: this.status, |
This file contains 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
document.addEventListener('keydown' ,function (e) { | |
if (e.which === 9) { | |
setTimeout(function() { | |
console.log(document.activeElement); | |
}, 100); | |
} | |
}); |
This file contains 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
function duplicateArray(newArray, array, times) { | |
for (var i = 0; i < times; i++) { | |
newArray = newArray.concat(array); | |
} | |
return newArray; | |
} |
This file contains 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
'use strict'; | |
module.exports = function () { | |
return function(file, callback, errorCallback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.callback = callback; | |
if (xhr.overrideMimeType) { | |
xhr.overrideMimeType('application/json'); | |
} |
This file contains 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
const Handlebars = require('handlebars'); | |
const makeRequest = require('./make-xhr'); | |
module.exports = function hbsUtilities() { | |
function loadTemplate(url, callback) { | |
var hbsTmplRequest = makeRequest('GET', url); | |
hbsTmplRequest.then(function success(data) { | |
callback(data); | |
}, function failure(errorData) { |
This file contains 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
// idea taken from http://stackoverflow.com/questions/8691756/how-can-i-test-the-users-computers-processing-power-using-javascript | |
isGoodPerformance: function isGoodPerformance(benchMarkTestFunction) { | |
var _startTime = new Date().getTime(); | |
benchMarkTestFunction(); // render frame for example | |
var _endTime = new Date().getTime(); | |
var _elapsedMilliseconds = _endTime - _startTime; | |
var _acceptableTime = 1000; // one second | |
return _elapsedMilliseconds < _acceptableTime; // some number being acceptable performace | |
} |
This file contains 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
p5.SoundFile.prototype.setVolume = function (vol, rampTime, tFromNow, volFrom, volTo) { | |
if (typeof vol === 'number') { | |
var rampTime = rampTime || 0; | |
var tFromNow = tFromNow || 0; | |
var now = p5sound.audiocontext.currentTime; | |
var currentVol = this.output.gain.value; | |
this.output.gain.cancelScheduledValues(now + tFromNow); | |
// Attack | |
if (typeof volFrom === 'number' && volFrom >= 0) { | |
this.output.gain.linearRampToValueAtTime(volFrom, now + tFromNow); |
This file contains 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
/** | |
* returns the largest positive number in a given array | |
* @param {Array} arr [the array to act on] | |
* @return {Array} [the largest number] | |
*/ | |
function getLargestPosNumInArr(arr) { | |
return arr.reduce(function(prevVal, curVal) { | |
if (curVal > prevVal) { | |
prevVal = curVal; | |
} |
This file contains 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
/** | |
* returns the largest negative number in a given array | |
* @param {Array} arr [the array to act on] | |
* @return {Number} [the largest negative number] | |
*/ | |
function getLargestNegNumInArr(arr) { | |
return arr.reduce(function(prevVal, curVal) { | |
if (curVal < prevVal) { | |
prevVal = curVal; | |
} |
This file contains 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
// Main thread | |
var test = document.getElementById('test'); | |
drawWorker = work(require('./draw-worker.js')); | |
drawWorker.addEventListener('message', function(e) { | |
if (e.data.msg === 'tick') { | |
sketchUpdateFn(); | |
} | |
}); | |
drawWorker.postMessage({draw: true, rate: appFrameRate}); | |
drawWorker.onerror = function(e) { |
OlderNewer