condensed the display method to be reusable - would really come in handy after I create the RGB to HSL transformation
This commit is contained in:
parent
de7059f52e
commit
3ab509a368
1 changed files with 29 additions and 58 deletions
87
js/franz.js
87
js/franz.js
|
|
@ -82,19 +82,6 @@ var franz = {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
displayImg: function() {
|
|
||||||
var docString = "";
|
|
||||||
|
|
||||||
for(var i = 0; i < franz.alpha.length; i++) {
|
|
||||||
docString += '<div class="color_box" style="background-color: rgb(' + franz.red[i] + ', ' + franz.green[i] + ',' + franz.blue[i] + ');"></div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById("log_colors").innerHTML = docString;
|
|
||||||
$("#container_bottom").fadeIn("slow");
|
|
||||||
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
/* Converts RGB to the Hue/Saturation/Value model */
|
/* Converts RGB to the Hue/Saturation/Value model */
|
||||||
RGBtoHSV: function() {
|
RGBtoHSV: function() {
|
||||||
|
|
@ -147,19 +134,13 @@ var franz = {
|
||||||
return hue;
|
return hue;
|
||||||
},
|
},
|
||||||
|
|
||||||
displayHue: function() {
|
|
||||||
|
/* routines to display color swatches */
|
||||||
|
displayColors: function(order_array) {
|
||||||
var docString = "";
|
var docString = "";
|
||||||
|
|
||||||
/* keep track of original index so we don't have to revert
|
|
||||||
back to RGB just to display output */
|
|
||||||
for (var i=0; i < franz.alpha.length; i++) {
|
|
||||||
franz.origIndex[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
franz.qsort(franz.clone(franz.hue), 0, franz.alpha.length);
|
|
||||||
|
|
||||||
for(var i = 0; i < franz.alpha.length; i++) {
|
for(var i = 0; i < franz.alpha.length; i++) {
|
||||||
docString += '<div class="color_box" style="background-color: rgb(' + franz.red[franz.origIndex[i]] + ', ' + franz.green[franz.origIndex[i]] + ',' + franz.blue[franz.origIndex[i]] + ');"></div>';
|
docString += '<div class="color_box" style="background-color: rgb(' + franz.red[order_array[i]] + ', ' + franz.green[order_array[i]] + ',' + franz.blue[order_array[i]] + ');"></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("log_colors").innerHTML = docString;
|
document.getElementById("log_colors").innerHTML = docString;
|
||||||
|
|
@ -167,51 +148,41 @@ var franz = {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
resetIndex: function() {
|
||||||
displaySat: function() {
|
|
||||||
var docString = "";
|
|
||||||
|
|
||||||
/* keep track of original index so we don't have to revert
|
/* keep track of original index so we don't have to revert
|
||||||
back to RGB just to display output */
|
back to RGB just to display output */
|
||||||
for (var i=0; i < franz.alpha.length; i++) {
|
for (var i=0; i < franz.alpha.length; i++) {
|
||||||
franz.origIndex[i] = i;
|
franz.origIndex[i] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
franz.qsort(franz.clone(franz.sat), 0, franz.alpha.length);
|
|
||||||
|
|
||||||
for(var i = 0; i < franz.alpha.length; i++) {
|
|
||||||
docString += '<div class="color_box" style="background-color: rgb(' + franz.red[franz.origIndex[i]] + ', ' + franz.green[franz.origIndex[i]] + ',' + franz.blue[franz.origIndex[i]] + ');"></div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById("log_colors").innerHTML = docString;
|
|
||||||
$("#container_bottom").fadeIn("slow");
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
displayVal: function() {
|
displayImg: function() {
|
||||||
var docString = "";
|
franz.resetIndex();
|
||||||
|
franz.displayColors(franz.origIndex);
|
||||||
/* keep track of original index so we don't have to revert
|
return false;
|
||||||
back to RGB just to display output */
|
},
|
||||||
for (var i=0; i < franz.alpha.length; i++) {
|
displayHue: function() {
|
||||||
franz.origIndex[i] = i;
|
franz.resetIndex();
|
||||||
}
|
franz.qsort(franz.clone(franz.hue), 0, franz.alpha.length);
|
||||||
|
franz.displayColors(franz.origIndex);
|
||||||
franz.qsort(franz.clone(franz.val), 0, franz.alpha.length);
|
return false;
|
||||||
|
},
|
||||||
for(var i = 0; i < franz.alpha.length; i++) {
|
displaySat: function() {
|
||||||
docString += '<div class="color_box" style="background-color: rgb(' + franz.red[franz.origIndex[i]] + ', ' + franz.green[franz.origIndex[i]] + ',' + franz.blue[franz.origIndex[i]] + ');"></div>';
|
franz.resetIndex();
|
||||||
}
|
franz.qsort(franz.clone(franz.sat), 0, franz.alpha.length);
|
||||||
|
franz.displayColors(franz.origIndex);
|
||||||
document.getElementById("log_colors").innerHTML = docString;
|
return false;
|
||||||
$("#container_bottom").fadeIn("slow");
|
},
|
||||||
|
displayVal: function() {
|
||||||
|
franz.resetIndex();
|
||||||
|
franz.qsort(franz.clone(franz.val), 0, franz.alpha.length);
|
||||||
|
franz.displayColors(franz.origIndex);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/* quicksort algorithm with that also swaps original index */
|
/* quicksort algorithm that also swaps an index array */
|
||||||
sort_Partition: function(array, begin, end, pivot) {
|
sort_Partition: function(array, begin, end, pivot) {
|
||||||
var piv=array[pivot];
|
var piv=array[pivot];
|
||||||
array.swap(pivot, end-1);
|
array.swap(pivot, end-1);
|
||||||
|
|
|
||||||
Reference in a new issue