sort function with a few logs to show data inconsistency.
This commit is contained in:
parent
c26fdfb105
commit
8351f9b6bf
2 changed files with 16 additions and 43 deletions
|
|
@ -41,7 +41,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#try_these a").click(function() {
|
$("#try_these a").click(function() {
|
||||||
img_input.value = this.innerHTML;
|
img_input.value = "awesome/" + this.innerHTML;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -95,7 +95,7 @@
|
||||||
<input type="submit" class="img_submit" value="Upload and be awesome">
|
<input type="submit" class="img_submit" value="Upload and be awesome">
|
||||||
</form>
|
</form>
|
||||||
<form method="post" action="#" id="franz_form">
|
<form method="post" action="#" id="franz_form">
|
||||||
<input type="text" id="img_input" value="lol.png">
|
<input type="text" id="img_input" value="awesome/lol.png">
|
||||||
<input type="submit" class="img_submit" value="Go for it!">
|
<input type="submit" class="img_submit" value="Go for it!">
|
||||||
</form>
|
</form>
|
||||||
<p id="try_these"><strong>Try out:</strong>
|
<p id="try_these"><strong>Try out:</strong>
|
||||||
|
|
|
||||||
55
js/franz.js
55
js/franz.js
|
|
@ -117,8 +117,8 @@ var franz = {
|
||||||
max = Math.max(red,Math.max(green,blue));
|
max = Math.max(red,Math.max(green,blue));
|
||||||
delta = max - min;
|
delta = max - min;
|
||||||
|
|
||||||
if (max == 0)
|
if (max == min)
|
||||||
return -1;
|
return 0;
|
||||||
else {
|
else {
|
||||||
if (red == max)
|
if (red == max)
|
||||||
hue = (green - blue) / delta; //between yellow & magenta
|
hue = (green - blue) / delta; //between yellow & magenta
|
||||||
|
|
@ -200,78 +200,51 @@ var franz = {
|
||||||
},
|
},
|
||||||
|
|
||||||
displayHue: function() {
|
displayHue: function() {
|
||||||
franz.bubbleSort(franz.clone(franz.hsvl.hue), 0, franz.rgb.alpha.length);
|
franz.indexSort(franz.clone(franz.hsvl.hue), 0, franz.rgb.alpha.length);
|
||||||
franz.displayColors(franz.origIndex);
|
franz.displayColors(franz.origIndex);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
displaySat: function() {
|
displaySat: function() {
|
||||||
franz.bubbleSort(franz.clone(franz.hsvl.satV), 0, franz.rgb.alpha.length);
|
franz.indexSort(franz.clone(franz.hsvl.satV), 0, franz.rgb.alpha.length);
|
||||||
franz.displayColors(franz.origIndex);
|
franz.displayColors(franz.origIndex);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
displayVal: function() {
|
displayVal: function() {
|
||||||
franz.bubbleSort(franz.clone(franz.hsvl.value), 0, franz.rgb.alpha.length);
|
franz.indexSort(franz.clone(franz.hsvl.value), 0, franz.rgb.alpha.length);
|
||||||
franz.displayColors(franz.origIndex);
|
franz.displayColors(franz.origIndex);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
displaySatL: function() {
|
displaySatL: function() {
|
||||||
franz.bubbleSort(franz.clone(franz.hsvl.satL), 0, franz.rgb.alpha.length);
|
franz.indexSort(franz.clone(franz.hsvl.satL), 0, franz.rgb.alpha.length);
|
||||||
franz.displayColors(franz.origIndex);
|
franz.displayColors(franz.origIndex);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
displayLight: function() {
|
displayLight: function() {
|
||||||
franz.bubbleSort(franz.clone(franz.hsvl.light), 0, franz.rgb.alpha.length);
|
franz.indexSort(franz.clone(franz.hsvl.light), 0, franz.rgb.alpha.length);
|
||||||
franz.displayColors(franz.origIndex);
|
franz.displayColors(franz.origIndex);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
/* bubble sort */
|
/* bubble sort floats around and pops in your face */
|
||||||
bubbleSort: function(inputArray, start, end) {
|
indexSort: function(inputArray, start, end) {
|
||||||
franz.resetIndex();
|
franz.resetIndex();
|
||||||
for (var i = start; i < end; i++) {
|
for (var i = start; i < end; i++) {
|
||||||
for (var j = start; j < end; j++) {
|
for (var j = end-1; j >= start; j--) {
|
||||||
var diff = inputArray[j] - inputArray[i]
|
var diff = inputArray[j] - inputArray[i]
|
||||||
|
console.log("j=" + inputArray[j] + " i=" + inputArray[i] + " -> " + diff);
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
|
console.log("swapped");
|
||||||
inputArray.swap(i,j+1);
|
inputArray.swap(i,j+1);
|
||||||
franz.origIndex.swap(i,j+1);
|
franz.origIndex.swap(i,j+1);
|
||||||
}
|
}
|
||||||
|
if (j == end-20) break;
|
||||||
}
|
}
|
||||||
|
if (i == 20) break;
|
||||||
}
|
}
|
||||||
},
|
|
||||||
/* quicksort algorithm that also swaps an index array */
|
|
||||||
sort_Partition: function(array, begin, end, pivot) {
|
|
||||||
var piv=array[pivot];
|
|
||||||
array.swap(pivot, end-1);
|
|
||||||
franz.origIndex.swap(pivot, end-1);
|
|
||||||
var store=begin;
|
|
||||||
var ix;
|
|
||||||
for(ix=begin; ix<end-1; ++ix) {
|
|
||||||
if(array[ix]<=piv) {
|
|
||||||
array.swap(store, ix);
|
|
||||||
franz.origIndex.swap(store, ix);
|
|
||||||
++store;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
array.swap(end-1, store);
|
|
||||||
franz.origIndex.swap(end-1, store);
|
|
||||||
|
|
||||||
return store;
|
|
||||||
},
|
|
||||||
|
|
||||||
qsort: function(array, begin, end) {
|
|
||||||
if(end-1>begin) {
|
|
||||||
var pivot=begin+Math.floor(Math.random()*(end-begin));
|
|
||||||
|
|
||||||
pivot=franz.sort_Partition(array, begin, end, pivot);
|
|
||||||
|
|
||||||
franz.qsort(array, begin, pivot);
|
|
||||||
franz.qsort(array, pivot+1, end);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue