Random color code

hey … pom, beta … someone;

shouldn’t this code


onClipEvent(enterFrame){
	this.setRGB(Math.random(16777215/11));
}

apply a random color to the movie clip it’s attached to when it enters the frame?

i’m trying to combine things i’ve learned from several tutorials to get an effect and i’ve almost got it =)

thanks in advance for the help

onClipEvent(enterFrame) {}
executes the actions every frame. Like if your fps is 20 then the actions will be executed 20 times per second.

hey shuga!

u cant setRGB simply like this, it should look like:

Color = new Color(Movie);
Color.setRGB(16777215);

i dont think math.random will work with that one, cuz it will create decimals!

I put this as a variable definition in the frame’s code


Color = new Color(image);
Color.setRGB(Math.random(16777215));

then i attached this code to the symbol itself


onClipEvent(enterFrame){
this.Color
}

and now it turns them all black … which means the color set is working but it’s not choosing a new random color each time.

and about it being executed 20 times a second. I have stops on each frame. the movie chooses one of 32 frames to randomly stop on but I want each frame to have a different color clip on it so I want it to set the color randomly each time it enters the frame

=)

help

its Showing black cuz its a DECIMAL

enterFrame has nothing to do with the timeline or frames.
It just executes the actions as fast as the frames per second
the timeline may not play but it still executes them so fast.
and try making the setRGB action like this:

**myColor** = new Color(<movielip>);
**myColor**.setRGB(**0x**+(**Math.random()*(16777215/11)**));

but 0x in front of the color value and I think you need to change the Color too cuz a function is named that way too. But maybe you don’t need to change it… experiment :slight_smile:

I believe setRGB is expecting hex.

Are you looking for one of 16 million colors? Just wondering?

you could also do this…

R = random number between 0 and 255

G = random number between 0 and 255

B = random number between 0 and 255

then use this formula


mycolor.setRGB(R<<16 | g<<8 | b);

try it out!

i’ll try it but i don’t understand why you did

R<<16 | g<<8 | b

explain what this does please =)

also, i think i’ve seen this somewhere before but i tried it and i couldnt make it work although i’m sure it’s my syntax. if it’s expecting hex why couldn’t i do random(x*ffffff) ?

ho yeah! setRGB is like 0xFFFFFF or 0x000000
0xRRGGBB

400 POSTS

happily you can!

myColor.setRGB(Math.random()*0xffffff);

will work just dandy.

genius!!

that’s the code i was looking for.

thank you so much!

wow! You learn something new every day, especially from Supra.

i learned that from this board!

from a post by ily i think…

Ilyas put it up on Kirupas site under AS Tricks :slight_smile:

here’s the file if anyone wants to see how it’s done =)

Oh yeah… this also produce a very nice effect…

onClipEvent (enterFrame) {
	red = Math.sin(ra += .02)*127+128;
	green = Math.sin(rb += .05)*127+128;
	blue = Math.sin(rc += .09)*127+128;
	myCol = red << 16 | green << 8 | blue;
	myColored = new Color(this);
	myColored.setRGB(myCol);
}

good job, like it ;)!

neat.

Shuga, just a comment, if you don’t mind. Even Repeat visitors to your site will not notice that your rocks are random. I really like the concept, maybe you should change the rocks at randon intervals, or have them show up periodically…dunno… Again, nice concept.

Hope you don’t mind the humble suggestion.

thanks, i’ll try that.

so you don’t think the regenerate button in the bottom right will make a difference?

thanks beta, i’ll try that too =)

No problem, I hope you enjoy that code :slight_smile:

I believe I got it from Ilyas… :slight_smile:

I made a correction to the code.

I accidently had onClipEvent (onEnterFrame)…lol, I am so used to using onEnterFrame = function() now… so I just removed the on and made the E an e.