In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Rainbow Ring

Get Adobe Flash player
by yasnis 15 Feb 2009
package {
    import flash.display.*;
    import flash.text.TextField;
    import flash.events.Event;
    import flash.filters.*;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            initialize();
	    var c:Shape;
	    var p:Object;
            var l:int = 3;
	    for (var i:int = 0; i < l; i++) {
	    	c = createCircle(70 + 10 * Math.random());
	    	p = new Object();
	    	p.r = 5 + 15 * Math.random();
	    	p.theta = Math.random() * PI * 2;
	    	p.vtheta = Math.random() * PI / 180*15;
	    	balllist[i] = c;
	    	poslist[i] = p;
	    	holder.addChild(c);
	    }
	    addEventListener(Event.ENTER_FRAME, update);
        }
        private function initialize():void {
            center.x = stage.stageWidth/2>>0;
            center.y = stage.stageHeight/2>>0;
            var s:Shape = new Shape();
            var g:Graphics = s.graphics;
            g.beginFill(0x000000);
            g.drawRect(0,0,100,100);
            s.width = stage.stageWidth;
            s.height = stage.stageHeight;
            addChildAt(s,0);
	    holder = new Sprite();
	    addChild(holder);
            blur = new BlurFilter(4, 4, 1);
	    glow = new GlowFilter(0xffffff, .3, 32, 32, 1, 2);
	    holder.filters = [blur ,glow];
            holder.visible = false;
            holder.blendMode = BlendMode.ADD;
            bmpd = new BitmapData(stage.stageWidth,stage.stageHeight,true,0xff000000);
            bmp = new Bitmap(bmpd);
            bmp.blendMode = BlendMode.ADD;
            addChildAt(bmp,1);
        }
	private function update(e:Event):void {
            if(++count% interval==0){
                huemarker += Math.random()*180;
                interval = Math.random()*20+20;
                count = 0;
            }
            hue += (huemarker-hue)*0.1;
            glow.color = getRGB(hue,saturation,blightness);
	    holder.filters = [blur ,glow];
	    var c:Shape;
	    var p:Object;
            var l:int = balllist.length;
	    for (var i:int = 0; i < l; i++) {
                c = balllist[i];
                p = poslist[i];
                p.theta+=p.vtheta;
                c.x = p.r*Math.cos(p.theta)+center.x;
                c.y = p.r*Math.sin(p.theta)+center.y;
	    }
            bmpd.draw(holder, null, null, BlendMode.ADD);
            bmpd.applyFilter(bmpd, bmpd.rect, bmpd.rect.topLeft, cmf);
	}
        public function createCircle(r:Number):Shape{
            var s:Shape = new Shape();
	    var g:Graphics = s.graphics;
	    g.beginFill(0x000000);
	    g.drawCircle(0, 0, r);
	    return s;
        }
	public const RGB_MAX:int = 255; public const H_MAX:int = 360; public const SB_MAX:int = 100;
	public function getRGB(h:Number = 0, s:Number = 100 , b:Number=100):uint {
	    h = h % H_MAX >> 0;
	    s = Math.max(0, Math.min(s , SB_MAX));
	    b = Math.max(0, Math.min(b , SB_MAX));
	    var red:Number,green:Number,blue:Number;
	    if (s == 0){
	    	red = green = blue = b*RGB_MAX/SB_MAX;
	    }else{
	    	var hi:Number = Math.floor(h / (H_MAX / 6)) % 6;
	    	var f:Number = h / (H_MAX / 6) - hi;
	    	var p:Number = b / SB_MAX * ( 1 - s / SB_MAX );
		var q:Number = b / SB_MAX * ( 1 - s / SB_MAX  * f);
		var t:Number = b / SB_MAX * ( 1 - s / SB_MAX  * ( 1 - f));
		switch (hi) { 
	            case 0 : red = b / SB_MAX; green = t; blue = p; break; 
		    case 1 : red = q; green = b / SB_MAX; blue = p; break;
		    case 2 : red = p; green = b / SB_MAX; blue = t; break; 
		    case 3 : red = p; green = q; blue = b / SB_MAX; break; 
		    case 4 : red = t; green = p; blue = b / SB_MAX; break; 
		    case 5 : red = b / SB_MAX; green = p; blue = q; break; 
		}
                red = Math.round(red * RGB_MAX);
	        green = Math.round(green * RGB_MAX);
	        blue = Math.round(blue * RGB_MAX);
	    }
	    return red << 16 | green << 8 | blue;
	}
	private const PI:Number = Math.PI;
        private var holder:Sprite;
        private var balllist:Array = [];
        private var poslist:Array = [];
	private var center:Object = {};
        private var glow:GlowFilter;
        private var blur:BlurFilter;
        private var huemarker:Number = Math.random()*360;
        private var hue:Number = Math.random()*360;
        private var saturation:Number = 100;
        private var blightness:Number = 100;
        private var bmpd:BitmapData;
        private var bmp:Bitmap;
        private var count:int = 0;
        private var interval:int = Math.random()*30+30;
	private const cmf:ColorMatrixFilter = new ColorMatrixFilter([
	    1, 0, 0, 0, 0,
	    0, 1, 0, 0, 0,
	    0, 0, 1, 0, 0,
	    0, 0, 0, .9, 0
        ]);
    }
}