How could I create a color array with javascript? -


i'm trying create array holds random colors, 1 random color per variable in array. when call variable in array gives me random color.

here instructions khan academy:

"to make animation of rain, it's best if use arrays keep track of drops , different properties. start simple code , build on make cool rain animation. here ideas do:

add more drops arrays. make drops start @ top once they've reached bottom, using conditional. make array of colors, every drop different color. make other things rain, snowflakes (using more shape commands) or avatars (using image commands). make when user clicks, new drop added array. initialize arrays using loop , random() function, @ beginning of program."

i want create of sort.

var color = [color1,color2,color3]; 

how make work? i'm beginning learn arrays.

this have far.

//this program creates raindrops each different color. var xpositions = [100,200,300];//1. added drops var ypositions = [0,0,0]; var dropcolors = [???,???,???];  draw = function() {     background(201, 247, 255);      //additional raindrops produced when mouse pressed     if (mouseispressed) {         xpositions.push(mousex);         ypositions.push(0);     }     (var = 0; < xpositions.length; i++) {         nostroke();         fill(100, 100, 100);         ellipse(xpositions[i], ypositions[i], 10, 10);         //speed @ raindrops fall.         ypositions[i] += 5;         //2. drop restarts @ initial yposition.         if(ypositions[i] === 400){             ypositions[i] = 0;             //random xposition             xpositions[i] = random(0,400);         }     }  }; 

thank you.

//this program creates raindrops each different color. var xpositions = [0,100,200,300,400];//1. added drops var ypositions = [0,100,200,300,400]; var dropcolors = [color(random(0,255),random(0,255),random(0,255)),                   color(random(0,255),random(0,255),random(0,255)),                   color(random(0,255),random(0,255),random(0,255))];  draw = function() {     background(201, 247, 255);      //additional raindrops produced when mouse pressed     if (mouseispressed) {         xpositions.push(mousex);         ypositions.push(mousey);         dropcolors.push(color(random(0,255),random(0,255),random(0,255)));     }     (var = 0; < xpositions.length; i++) {         nostroke();         fill(dropcolors[i]);         ellipse(xpositions[i], ypositions[i], 10, 10);         //speed @ raindrops fall.         ypositions[i] += 5;         //2. drop restarts @ initial yposition.         if(ypositions[i] === 400){             ypositions[i] = 0;             //random xposition             xpositions[i] = random(0,400);             var randindex = floor(random(dropcolors.length));             var adropcolors = dropcolors[randindex];             dropcolors[i] = adropcolors;         }     }  }; 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -