dynamic color array
in
Programming Questions
•
8 months ago
hi there,
im new to processing and im trying to create a dynamic array of colors
basically, as float indirectness varies from 0 to 1, I want the array to change size. So if indirectness=
0, then I want the colorarray to only have 2 colors but if indirectness gets closer to 1 then I want colorarray to grow in size
for right now I am using a predefined list of colors but I may eventually want to use ArrayList() or vector()
Is there a better way to do this?
color[] colorarray=new color[12];
float indirectness = random(0,1);
int colorlookup;
void setup()
{
size(640, 480);
// for now just using a standard array
//just using random colors for now
colorarray[0]=color(255, 100, 100);
colorarray[1]=color(235, 100, 100);
colorarray[2]=color(215, 100, 100);
colorarray[3] = color(195, 100, 100);
colorarray[4] = color(175, 100, 100);
colorarray[5] = color(155, 100, 100);
colorarray[6] = color(135, 100, 100);
colorarray[7] = color(115, 100, 100);
colorarray[8] = color(95, 100, 100);
colorarray[9] = color(75, 100, 100);
colorarray[10] = color(55, 100, 100);
colorarray[11] = color(35, 100, 100);
colorlookup= int(indirectness*colorarray.length);
//colorlookup = indirect*colorarray.size, if we use arraylist()
}
void draw()
{
for(int i=0; i < colorlookup; i++)
{
color currentcolor = colorarray[(int) random(0, colorlookup)];
fill(currentcolor);
rect(0, 0, 50, 50);
//
fill(colorarray[3]);
rect (width/8, height/8, 50, 50);
fill(colorarray[5]);
rect (width/4, height/4, 50, 50);
fill(colorarray[11]);
rect (width/2, height/2, 50, 50);
}
}
1