Colour changing effect in Rev's footer

Hi all,

I was just wondering how Rev did the colour changing effect in his current footer?

Reminds me of my ZX Spectrum games, and I wan’t to play around with this effect.

I assume there is actionscript code involved in this effect?

Cheers :slight_smile:

I got it from a thread that Ilyas made, where he stated that he ‘borrowed’ it from Bit-101’s site.

so, you can do a search for it here, or go straight to the source, Bit-101 …

Rev

Cycling colors tutorial: :beam:

First, create a dot:

this.createEmptyMovieClip ( "myClip", 0 ) ;
myClip.lineStyle ( 30, 0, 100 ) ;
myClip.lineTo ( .45, .15 ) ;

Then create the color cycle:

// Create a color object corresponding to the clip you want to apply setRGB to
myClip.colorClip = new Color ( myClip ) ;

myClip.onEnterFrame = function () {
	var r = 128 * ( 1 + Math.cos ( ra += .03 ) ) ;
	var g = 128 * ( 1 + Math.cos ( rg += .05 ) ) ;
	var b = 128 * ( 1 + Math.cos ( rb += .01 ) ) ;
	var myColor = r << 16 | g << 8 | b ;
	this.colorClip.setRGB ( myColor ) ;
}

The tricky part is in the onEnterFrame.
[FONT=courier new]var r = 128 * ( 1 + Math.cos ( ra += .03 ) ) ;[/FONT]
for instance, will return a number between 0 and 256, which is pretty much what we want since color components (green, red and blue) go from 0 to 255 (0 to FF in hexadecimal), 0 being ‘no color’ and 255 (or FF) being ‘full color’.

The Math.cos part does the cycling, because that function (just like Math.sin) returns cycling values between -1 and 1 (it’s a circular function).

Once we’ve calculated the 3 components of our color (r, g, b), we put them together with this very nice line:
[FONT=courier new]var myColor = r << 16 | g << 8 | b ;[/FONT]
It has to be in this order: Red, then Green, and then Blue, as in RGB. The << and | operators are bitwise operators, and they allow you to shift your color values properly, and then stick them together.

Tadaaa!! Finished :slight_smile:

Thanks Ilyas!

Sorry I didn’t thank you earlier, but I only just checked the thread.

I’ve just started learning Actionscript. My tutor just the other day showed me cycles using cos and sin, so I understand the code!

Thanks again! I’m going to have a play around now :slight_smile: