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

Wondering Pixels Dance

Get Adobe Flash player
by 0xFFFFFF 27 Dec 2010
/**
 * Copyright 0xFFFFFF ( http://wonderfl.net/user/0xFFFFFF )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/yIV2
 */

package {
    import flash.text.TextFieldAutoSize;
    import flash.text.TextField;
    import flash.geom.Matrix;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BitmapDataChannel;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import flash.filters.DisplacementMapFilter;
    import flash.geom.Point;
    import flash.media.Sound;
    import flash.media.SoundMixer;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;
    import flash.display.Sprite;
    import flash.system.Security;
    
    [SWF (width=400, height=400, backgroundColor=0)]
    public class Exp101227_01 extends MovieClip {
        
        private const W : Number = 400;
        private const H : Number = 400;
        private var output : BitmapData;
        private var map : BitmapData;
        private var pixels : Array = [];
        private var num : Number = 500;
        private var movePoint1 : Point = new Point(0, 0);
        private var movePoint2 : Point = new Point(0, 0);
        private var origin : Point = new Point(0, 0);
        private var blur : BlurFilter;
        private var sound : Sound;
        private var arr1 : ByteArray;
        private var arr2 : ByteArray;
        private var tf : TextField;
        
        public function Exp101227_01() {
            // write as3 code here..
            Security.loadPolicyFile("http://0xffffff.ru/crossdomain.xml");
           
            tf = new TextField();
            addChild(tf);
            tf.autoSize = TextFieldAutoSize.LEFT;
            tf.textColor = 0xffffff;
             
            
            output = new BitmapData(W, H, true, 0);
            map = new BitmapData(W/2, H/2);

            for (var i : Number = 0;i < num;i++)
            {
                var p : Object = {x:Math.random() * W, y:Math.random() * H, speed:25, t:0};
                pixels.push(p);
            }

            addChild(new Bitmap(output));

            blur = new BlurFilter(3, 3, 3);

            sound = new Sound(new URLRequest("http://0xffffff.ru/flash/exp/as3/musical/wonderingpixelsdance/06.mp3"));
            sound.play(0,99);

            arr1 = new ByteArray();
            arr2 = new ByteArray();

            addEventListener(Event.ENTER_FRAME, loop);
            loop();
        }
        
        private function loop(event : Event = null) : void
        {
            if(!SoundMixer.areSoundsInaccessible())
            {
                tf.text = '';
                SoundMixer.computeSpectrum(arr1);
                SoundMixer.computeSpectrum(arr2, true);
    
                map.perlinNoise(50, 50, 2, 6, true, true, BitmapDataChannel.RED | BitmapDataChannel.BLUE, false, [movePoint1, movePoint2]);
                movePoint1.offset(.5, .1);
                movePoint2.offset(.2, -.5);
    
                var tmpMap : BitmapData = new BitmapData(W, H);
                var m:Matrix = new Matrix();
                m.scale(2, 2);
                tmpMap.draw(map,m,null, null, null, true);
                var displace : DisplacementMapFilter = new DisplacementMapFilter(tmpMap, origin, BitmapDataChannel.RED, BitmapDataChannel.BLUE, -3, -3);
                
                
                for (var i : Number = 0; i < num; i++)
                {
                    var f1 : Number = arr1.readFloat();
                    var f2 : Number = arr2.readFloat();
    
                    var p : Object = pixels[i];
                    var c : int = map.getPixel(p.x/2, p.y/2);
                    //tf.text = c.x.toString();
                    
                    var red : Number = ((c & 0xff0000)>>16)- 128 + Math.random() * 6 - 3;      
                    
                    var blue : Number = (c & 0x0000ff) - 128 + Math.random() * 6 - 3;
    
                    p.x += red / p.speed * (Math.abs(f2) * 10 + .2);
                    p.y += blue / p.speed * (Math.abs(f2) * 10 + .2);
                    
                    tf.text = String(f2);
    
                    if (p.x > W) p.x -= W ;
                    if (p.x < 0) p.x += W ;
                    if (p.y > H) p.y -= H ;
                    if (p.y < 0) p.y += H ;
                    //if (f2 > 0)
                        p.t = 50;
    
                    if (p.t > 0)
                    {
                        // var color:uint = ((0xff)<<16<<8 ) | 0x1166FF00;
                        output.setPixel32(p.x, p.y, ((p.t / 50 * 0xff) << 16 << 8 ) | 0x00CCFF);
                        // trace((color).toString(16));
                        // output.setPixel32(p.x, p.y, ((p.t/100*0xff)<<32 ) | 0x66FF00);
                        // output.setPixel32(p.x, p.y, Number("0x"+(p.t/100*0xff)+"66FF00"));
                        // output.setPixel(p.x, p.y, 0x66FF00);
                        p.t--;
                    }
                }
                
                output.applyFilter(output, output.rect, origin, displace);
                tmpMap.dispose();
            } else {
                tf.text = 'sounds are inaccessable; please, close other flash sites with music';
            }
            
        }
    }
}