changing just saturation while leaving hue and brightness constant
in
Programming Questions
•
8 months ago
so I have set up a predefined list of colors in an array and I have almost got it working the way I like. Input ranges from 0 to 1. If input = .2 then the array of colors only has for example's sake 5 elements. If input =.9, then the array of colors gets bigger.
I don't want to do random generation of colors. I want to work with a predefined array.
My question is, how can I modify this code so that when input gets close to 1, saturation of the colors will reach the max value and when input is closer to 0 the saturation will get closer to its min value? And keep hue and brightness constant.
color[] colorarray=new color[22];
color[] myColors= new color[22];
int colorlookup;
void setupColors()
{
float input = random(0,1);
// if input = .2, the array only
colorMode(HSB, 360, 100, 100);
//HSV values
colorarray[0]= color(0,0,0);
colorarray[1]= color(200,1,83);
//brownberry
colorarray[2] = color(233, 40, 32);
colorarray[3] = color(236, 59, 26);
colorarray[4] = color(47, 5, 53);
colorarray[5] = color(54, 18, 100); //white
colorarray[6] = color(32, 52, 32); //gray
//northern lights by aguanno
colorarray[7] = color(247, 55, 25);
colorarray[8] = color(248, 22, 95);
colorarray[9] = color(225, 48, 65);
colorarray[10] = color(163, 29, 95);
colorarray[11] = color(141, 44, 65);
//aurora6
colorarray[12] = color(195, 61, 56);
colorarray[13] = color(54, 38, 98);
colorarray[14] = color(19, 62, 98);
colorarray[15] = color(4, 75, 89);
colorarray[16] = color(209, 100, 20);
//psychedelic by nobu
colorarray[17] = color(354, 100, 100);
colorarray[18] = color(54, 100, 100);
colorarray[19] = color(79, 93, 85);
colorarray[20] = color(204, 100, 100);
colorarray[21] = color(341, 89, 97);
colorlookup= int(input*colorarray.length) -1;
//if using arraylist use colorarray.size
}
color getColor(float directness)//arg
{
//remakeColors(directness);
//remakeColors(directness);
return colorarray[(int) random(0, colorlookup)];
//return colorarray[(int)(10.0*random(0,1))];
}
void remakeColors( float input )
{
myColors = new color[ int( map( input, 0, 1, 2, 500 ) ) ];
for ( int i=0; i<colorarray.length; i++)
{
myColors[i] = colorarray[((int) random(0, colorlookup))];
}
}
1