flash actionscript:
i have one mc. it is dynamically duplicated 100x and randomly distibuted across the stage. is there a way to randomly generate colors within a set color range instead of all colors -- for instance, just reds and yellows? this is what i'm using now. pretty straightforward. stop(); star2_mc._alpha = 50; for (i=3;i<=175;i++) { this.star2_mc.duplicateMovieClip("star"+i+"_mc",i); this["star"+i+"_mc"]._x = random(550); this["star"+i+"_mc"]._y = random(400); this["star"+i+"_mc"]._alpha = random(75); star_color = new Color("star"+i+"_mc"); star_color.setRGB(Math.floor(Math.random()*16000000)); }
myColors = [0xFFFF00,0xFF0000]; stop(); star2_mc._alpha = 50; for (i=3;i<=175;i++) { this.star2_mc.duplicateMovieClip("star"+i+"_mc",i); this["star"+i+"_mc"]._x = random(550); this["star"+i+"_mc"]._y = random(400); this["star"+i+"_mc"]._alpha = random(75); star_color = new Color("star"+i+"_mc"); star_color.setRGB(myColors[Math.floor(Math.random()*myColors.length)]); }
would you have a solution byron?
When he said, "just red and yellow", I assumed he meant just red and yellow. But, if it shouldn't be that way, then: startCol = 0xFF0000; endCol = 0x0000FF; dif = endCol-startCol+1; stop(); star2_mc._alpha = 50; for (i=3;i<=175;i++) { this.star2_mc.duplicateMovieClip("star"+i+"_mc",i); this["star"+i+"_mc"]._x = random(550); this["star"+i+"_mc"]._y = random(400); this["star"+i+"_mc"]._alpha = random(75); star_color = new Color("star"+i+"_mc"); star_color.setRGB(startCol+Math.floor(Math.random()*dif)); }
Here's a script that should mix colors, without having the entire color see through. Like in the previous scripts, if you change what is behind the mcs, the colors will change. Try this: Here's a script to get a mix of any amount of selected colors: //-Place colors to mix below: colorMix = [0xFFFF00,0xFF0000]; //-------------------------------------------- colorMix.unshift(0xFFFFFF); stop(); star2_mc._alpha = 50; for (i=3;i<=175;i++) { rx = random(550); ry = random(400); for(x=0;x<colorMix.length;x++){ this.star2_mc.duplicateMovieClip("star"+i+"_mc"+x,i*colorMix.length+x); ccolor = new Color(this["star"+i+"_mc"+x]); ccolor.setRGB(colorMix[x]); this["star"+i+"_mc"+x]._x = rx; this["star"+i+"_mc"+x]._y = ry; if(x==0){ this["star"+i+"_mc"+x]._alpha = 100; trace('colorMix.'+x+'='+(colorMix[x].toString(16))); }else{ this["star"+i+"_mc"+x]._alpha = random(100); } } }
And then there would be this way: for (i=3; i<=175; i++) { this.star2_mc.duplicateMovieClip("star"+i+"_mc", i); this["star"+i+"_mc"]._x = Math.floor(Math.random()*550); this["star"+i+"_mc"]._y = Math.floor(Math.random()*400); // this["star"+i+"_mc"]._alpha = Math.floor(Math.random()*75); nbrColor = Math.floor(Math.random()*0xFF)*0x100+0xFF0000; star_color = new Color("star"+i+"_mc"); star_color.setRGB(nbrColor); }
Don't see what you're looking for? Try a search.
|