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 Fork01

/**
 * Copyright 0xFFFFFF ( http://wonderfl.net/user/0xFFFFFF )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/tLEW
 */

// forked from makc3d's forked from: Wondering Pixels Dance
// forked from 0xFFFFFF's Wondering Pixels Dance
package {
    import flash.media.SoundChannel;
    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=465, height=465, backgroundColor=0)]
    public class Exp101227_01 extends MovieClip {
        
        private const W : Number = 465;
        private const H : Number = 465;
        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 channel:SoundChannel;
        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"));
            channel = sound.play (0, int.MAX_VALUE);

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

            addEventListener(Event.ENTER_FRAME, loop);
            loop();
        }
        
        private var displace : DisplacementMapFilter = new DisplacementMapFilter(new BitmapData (W, H), origin, BitmapDataChannel.RED, BitmapDataChannel.BLUE, -3, -3);
        private function loop(event : Event = null) : void
        {
            if(!SoundMixer.areSoundsInaccessible())
            {
                tf.text = '';
                SoundMixer.computeSpectrum(arr1);
                SoundMixer.computeSpectrum(arr2, true);
    
                map.perlinNoise(150, 150, 2, 6, true, true, BitmapDataChannel.RED | BitmapDataChannel.BLUE, false, [movePoint1, movePoint2]);
                movePoint1.offset(.5, .1);
                movePoint2.offset(.2, -.5);
    
                var m:Matrix = new Matrix();
                m.scale(2, 2);
                displace.mapBitmap.draw(map,m,null, null, null, true);
                
                var coef:Number = 1 + 2 * (channel.leftPeak + channel.rightPeak);
                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);
                    
                    //if (i == 10) tf.text = f2.toPrecision (4);
    
                    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, 0xFF000000 + hsv2rgb (f1*360));
                        
                        //output.setPixel32(p.x, p.y, 0xFF000000 + hsv2rgb ((1 + Math.atan2 (red, blue) / Math.PI)*180));
                        // 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--;
                    }
                }
                
                displace.scaleX = -3 * coef;
                displace.scaleY = -3 * coef;
                output.applyFilter(output, output.rect, origin, displace);
            } else {
                tf.text = 'sounds are inaccessable; please, close other flash sites with music';
            }
            
        }

        /**
         * @see http://wonderfl.net/c/dtn8
         * @author matacat
         */
        private function hsv2rgb(h:Number, s:Number = 1, v:Number = 1):uint
        {
            var rgb:uint = 0;

            if (s == 0) {  // gray scale
                rgb = 0xFF * v << 16 | 0xFF * v << 8 | 0xFF * v << 0;
                return rgb;
            }
            
            h = h >= 360 ? h % 360 : (h < 0 ? h % 360 + 360 : h);
            
            var i:int = int(h / 60);
            var f:Number = h / 60 - i;
            var p:Number = v * (1 - s);
            var q:Number = v * (1 - s * f);
            var t:Number = v * (1 - s * (1 - f));
            
            switch (i) {
                case 0: rgb = 0xFF * v << 16 | 0xFF * t << 8 | 0xFF * p << 0; break;
                case 1: rgb = 0xFF * q << 16 | 0xFF * v << 8 | 0xFF * p << 0; break;
                case 2: rgb = 0xFF * p << 16 | 0xFF * v << 8 | 0xFF * t << 0; break;
                case 3: rgb = 0xFF * p << 16 | 0xFF * q << 8 | 0xFF * v << 0; break;
                case 4: rgb = 0xFF * t << 16 | 0xFF * p << 8 | 0xFF * v << 0; break;
                case 5: rgb = 0xFF * v << 16 | 0xFF * p << 8 | 0xFF * q << 0;
            }

            return rgb;
        }
    }
}