07-23-2018, 08:52 AM
Code:
function nearestInstrument(color) {
RGBColor = color.slice(0, 3).map(x => x * color[3] / 255);
var result;
var smallest = Infinity;
for (i = 0; i < settings.numInstruments; i++) {
var difference = 0;
for (j = 0; j < 3; j++) {
difference += (settings.instrumentColors[i][j] - RGBColor[j]) ** 2;
}
if (smallest > difference) {
smallest = difference;
result = i;
}
}
return result;
}
function drawImg(source) {
var img = new Image();
img.src = source;
img.onload = function() {
canvas.width = 100;
canvas.height = 50;
canvas.getContext('2d').drawImage(img, 0, 0, canvas.width, canvas.height);
var total = ':';
for (var h = canvas.height - 1; h > -1; h--) {
for (var w = 0; w < canvas.width; w++) {
total += [w, piano50[h], 1, nearestInstrument(canvas.getContext('2d').getImageData(w, h, 1, 1).data)].join(' ') + ';';
}
}
if (typeof window.SequencerView == 'object') {
SequencerView.fastGraphics = true;
loadData(total);
$.each(audioSystem.instrumentVolume, x => audioSystem.setInstrumentVolume(x, 0));
} else {
console.log(total);
}
}
}
var piano50 = ["A6", "G#6", "G6", "F#6", "F6", "E6", "D#6", "D6", "C#6", "C6", "B5", "A#5", "A5", "G#5", "G5", "F#5", "F5", "E5", "D#5", "D5", "C#5", "C5", "B4", "A#4", "A4", "G#4", "G4", "F#4", "F4", "E4", "D#4", "D4", "C#4", "C4", "B3", "A#3", "A3", "G#3", "G3", "F#3", "F3", "E3", "D#3", "D3", "C#3", "C3", "B2", "A#2", "A2", "G#2"];
var canvas = document.createElement('canvas');
drawImg('/forum/uploads/avatars/avatar_9976.png');
BMOS v1.2 is here!
Kim Wrote:+ https://js-game.glitch.me + Doesnt take peopel serious if their has badly speling gramer puntuatin