Last active
December 20, 2015 20:59
-
-
Save biggestT/6193852 to your computer and use it in GitHub Desktop.
Toney snippets for development blog
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
getPlayerScore: function (line) { | |
if (this._referenceLine != null) { | |
var playerSize = line.getSize(); | |
var referenceSize = this._referenceLine.getSize(); | |
var longest = Math.max(playerSize[0], referenceSize[0]); | |
var highest = Math.max(Math.abs(playerSize[1]), Math.abs(referenceSize[1])); | |
var ratio = 0.5; // Importance of total line length VS total line slope: [0->1] | |
var xDiff = Math.abs(playerSize[0]-referenceSize[0]); | |
var yDiff = Math.abs(playerSize[1]-referenceSize[1]); | |
var xScore = (longest == 0) ? ratio * 1 : ratio * (1-xDiff/longest); | |
var yScore = (highest == 0) ? (1-ratio) * 1 : (1-ratio) * (1-yDiff/highest) ; | |
var starScore = Math.round(Math.min(xScore+yScore,1)*this.get('maxStars')); | |
this.trigger('game:newScore', starScore); | |
} | |
}, |
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
updateHighpassSpectrogram: function () { | |
var sum, filter, i, h, shift; | |
// filter = [-1, 3, -1]; | |
// filter = [ 1]; | |
filter = [-1, -1, 5, -1, -1]; | |
shift = Math.floor(filter.length/2); | |
this._highpassSpectrogram = []; | |
for (i = 0; i < this._spectrogram.length; i++) { | |
if (i > shift && i < this._spectrogram.length - shift) { | |
sum = 0; | |
for (h = 0; h < filter.length; h++) { | |
sum += filter[h]*this._spectrogram[i+h-shift]; | |
}; | |
sum /= filter.length; | |
sum = Math.min(Math.max(sum, 0), 128); | |
this._highpassSpectrogram[i] = sum; | |
} | |
else { | |
this._highpassSpectrogram[i] = this._spectrogram[i]; | |
} | |
}; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment