all groups > flash actionscript > january 2005 >
You're in the

flash actionscript

group:

creating random colors within set range



creating random colors within set range posterboy
1/14/2005 10:32:35 PM
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));
}
Re: creating random colors within set range NSurveyor
1/14/2005 10:45:03 PM
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)]);
}
Re: creating random colors within set range barn
1/14/2005 10:48:38 PM
Re: creating random colors within set range posterboy
1/14/2005 11:01:03 PM
would you have a solution byron?

Re: creating random colors within set range NSurveyor
1/14/2005 11:01:45 PM
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));
}
Re: creating random colors within set range NSurveyor
1/14/2005 11:06:13 PM
Re: creating random colors within set range posterboy
1/14/2005 11:07:52 PM
many thanks nsurveyor!

Re: creating random colors within set range posterboy
1/14/2005 11:15:11 PM
Re: creating random colors within set range NSurveyor
1/14/2005 11:40:02 PM
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);
}
}
}
Re: creating random colors within set range barn
1/14/2005 11:47:10 PM
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);
}
Re: creating random colors within set range NSurveyor
1/14/2005 11:49:17 PM
AddThis Social Bookmark Button