color matchBestHB(color[] pal, color col, float randomizer) {
int ind = 0;
float[] allB = new float[pal.length];
int nearest = -1;
int nextnearest = 0;
float bestDistanceFoundYet = 1;
float HBav = (hue(col)+brightness(col))/2;
for (int i=0; i<pal.length; i++) {
allB[i] = (hue(pal[i])+brightness(pal[i]))/2;
}
for (int i = 0; i < allB.length; i++) {
if (allB[i] == HBav) {
return pal[i];
} else {
// else, we consider the difference between the desired number and the current number in the array.
float d = abs(HBav - allB[i]);
if (d < bestDistanceFoundYet) {
bestDistanceFoundYet = d;
nextnearest = constrain(nearest,0,allB.length);
nearest = i;
}
}
}
//if (randomizer < palaltPercent) return pal[nextnearest];
return pal[nearest];
}
color matchBestHS(color[] pal, color col, float randomizer) {
int ind = 0;
float[] allB = new float[pal.length];
int nearest = -1;
int nextnearest = 0;
float bestDistanceFoundYet = 1;
float Hsav = (saturation(col)+hue(col))/2;
for (int i=0; i<pal.length; i++) {
allB[i] = (saturation(pal[i])+hue(pal[i]))/2;
}
for (int i = 0; i < allB.length; i++) {
if (allB[i] == Hsav) {
return pal[i];
} else {
// else, we consider the difference between the desired number and the current number in the array.
float d = abs(Hsav - allB[i]);
if (d < bestDistanceFoundYet) {
bestDistanceFoundYet = d;
nextnearest = constrain(nearest,0,allB.length);
nearest = i;
}
}
}
return pal[nearest];
}
color matchBestBS(color[] pal, color col, float randomizer) {
int ind = 0;
float[] allB = new float[pal.length];
int nearest = -1;
int nextnearest = 0;
float bestDistanceFoundYet = 1;
float HBav = (saturation(col)+brightness(col))/2;
for (int i=0; i<pal.length; i++) {
allB[i] = (saturation(pal[i])+brightness(pal[i]))/2;
}
for (int i = 0; i < allB.length; i++) {
if (allB[i] == HBav) {
return pal[i];
} else {
// else, we consider the difference between the desired number and the current number in the array.
float d = abs(HBav - allB[i]);
if (d < bestDistanceFoundYet) {
bestDistanceFoundYet = d;
nextnearest = constrain(nearest,0,allB.length);
nearest = i;
}
}
}
return pal[nearest];
}
color matchBestAll(color[] pal, color col) {
int ind = 0;
float[] allB = new float[pal.length];
int nearest = -1;
float bestDistanceFoundYet = 1;
float HBSav = (hue(col)+brightness(col)+saturation(col))/3;
for (int i=0; i<pal.length; i++) {
allB[i] = (hue(pal[i])+brightness(pal[i])+saturation(pal[i]))/3;
}
for (int i = 0; i < allB.length; i++) {
if (allB[i] == HBSav) {
return pal[i];
} else {
// else, we consider the difference between the desired number and the current number in the array.
float d = abs(HBSav - allB[i]);
if (d < bestDistanceFoundYet) {
bestDistanceFoundYet = d;
nearest = i;
}
}
}
return pal[nearest];
}
color matchBestH(color[] pal, color col, float randomizer) {
int ind = 0;
float[] allB = new float[pal.length];
int nearest = -1;
int nextnearest = 0;
float bestDistanceFoundYet = 1;
for (int i=0; i<pal.length; i++) {
allB[i] = hue(pal[i]);
}
for (int i = 0; i < allB.length; i++) {
//if (saturation(pal[i]) < 10) continue;
if (allB[i] == hue(col)) {
return pal[i];
} else {
// else, we consider the difference between the desired number and the current number in the array.
float d = abs(hue(col) - allB[i]);
if (d < bestDistanceFoundYet) {
bestDistanceFoundYet = d;
nextnearest = constrain(nearest,0,allB.length);
nearest = i;
}
}
}
return pal[nearest];
}
color matchBestB(color[] pal, color col, float randomizer) {
int ind = 0;
float[] allB = new float[pal.length];
int nearest = -1;
int nextnearest = 0;
float bestDistanceFoundYet = 1;
for (int i=0; i<pal.length; i++) {
allB[i] = brightness(pal[i]);
}
for (int i = 0; i < allB.length; i++) {
if (allB[i] == brightness(col)) {
return pal[i];
} else {
// else, we consider the difference between the desired number and the current number in the array.
float d = abs(brightness(col) - allB[i]);
if (d < bestDistanceFoundYet) {
bestDistanceFoundYet = d;
nextnearest = constrain(nearest,0,allB.length);
nearest = i;
}
}
}
return pal[nearest];
}