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

AcidAtractor

Get Adobe Flash player
by Murai 22 Sep 2010
/**
 * Copyright Murai ( http://wonderfl.net/user/Murai )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/yrXk
 */

// forked from Murai's TrippyAtractor
package {

    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageQuality;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.geom.ColorTransform;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundLoaderContext;
    import flash.media.SoundMixer;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;

    [SWF(backgroundColor="#FFFFFF", frameRate="60", width="465", height="465")]
    
       /**
     * @author Takashi Murai (KAYAC)
     */     
     
     /*
      * Free Music Archive: Digi G'Alessio - darix togni http://t.co/6TchjWv via
      * http://creativecommons.org/licenses/by-nc-nd/3.0/
      */

    public class AcidTrippyAtractor extends Sprite {


        private const N:uint = 10000;
        
        private var _a:Number;
        private var _b:Number;
        private var _c:Number;
        private var _d:Number;
        
        private var _va:Number = 1.0;
        private var _vb:Number = 1.0;
        private var _vc:Number = 1.0;
        private var _vd:Number = 1.0;
        
        private var _head:Particle;
        
        private var _canvas:BitmapData;
        private var _w:uint;
        private var _h:uint;
        
        private var snd:Sound;
        private var FFTswitch:Boolean = true;
        private var count:int;
        private var vol:Number;
        private var bmp:Bitmap;
        
        private var _trans:ColorTransform = new ColorTransform(1, 1, 1, 1, 0x4F, 0x4F, 0x4F);
        private var hexs:Array = [0x2e0927,0xd90000,0xff2d00,0xff8c00,0x04756f];
        private var bytes:ByteArray;

        function AcidTrippyAtractor() {

            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.quality = StageQuality.LOW;
            
            _w = 600;
            _h = 600;
                
            
            play("http://level0.kayac.com/images/murai/Digi_GAlessio_-_06_-_darix_togni.mp3");//A
            
            
            count = 0;
            
            /////
            
            var o:Particle = _head = new Particle();
            for (var i:uint = 0; i < N; ++i) {
                o = o.next = new Particle();
            }
            
            _canvas = new BitmapData(_w, _h, false, 0xffffff);
            bytes= new ByteArray();
            
            addChild(bmp = new Bitmap(_canvas));
            
            addEventListener(Event.ENTER_FRAME, _update);
            addEventListener(Event.ENTER_FRAME, render);
            stage.addEventListener(Event.RESIZE, resize);
            
            
            resize();
            change();
        }

        private function resize(e:Event = null) : void {
            bmp.x = stage.stageWidth / 2 - bmp.width / 2;
            bmp.y = stage.stageHeight / 2 - bmp.height / 2;
        }
        
        private function _reset():void {
            
            _a = (Math.random() - 0.5) * 3;
            _b = (Math.random() - 0.5) * 3;
            _c = (Math.random() - 0.5) * 6;
            _d = (Math.random() - 0.5) * 6;
            if (Math.abs(_a) < 0.8) _a += 0.8 * _a / Math.abs(_a);
            if (Math.abs(_b) < 0.8) _b += 0.8 * _b / Math.abs(_b);
            if (Math.abs(_c) < 1.0) _c += 1.0 * _c / Math.abs(_c);
            if (Math.abs(_d) < 1.0) _d += 1.0 * _d / Math.abs(_d);
            
            var p:Particle = _head;
            do {
                p.x0 = (Math.random() - 0.5) * 2;
                p.y0 = (Math.random() - 0.5) * 2;
            }
            while (p = p.next);
        }
        
        private function _update(e:Event):void {
            _canvas.lock();
            
            _canvas.colorTransform(_canvas.rect, _trans);
            
            var p:Particle = _head;
            do {
                p.x1 = Math.sin(_a * p.y0) + _c * Math.cos(_a * p.x0) + Math.random() * vol*2;
                p.y1 = Math.sin(_b * p.x0) + _d * Math.cos(_b * p.y0) + Math.random() * vol*2;
                p.x0 = p.x1;
                p.y0 = p.y1;

                _canvas.setPixel(_w / 2 + p.x1 * 70, _h / 2 + p.y1 * 70, hexs[((count++)/20000>>0) % 5]);
            }
            while (p = p.next);
            
            _canvas.unlock();
            
            if (_a < -3.0) _va = 1.0; else if (_a > 3.0) _va = -1.0;
            if (_b < -3.0) _vb = 1.0; else if (_b > 3.0) _vb = -1.0;
            if (_c < -3.0) _vc = 1.0; else if (_c > 3.0) _vc = -1.0;
            if (_d < -3.0) _vd = 1.0; else if (_d > 3.0) _vd = -1.0;
            _a += _va * 0.0010;
            _b += _vb * 0.0008;
            _c += _vc * 0.0004;
            _d += _vd * 0.0006;

        }

        private function change():void {
            _reset();
        }

        private function play(sndUrl:String):void {
            snd = new Sound();
            var context:SoundLoaderContext = new SoundLoaderContext(10, true);
            var req:URLRequest = new URLRequest(sndUrl);
            snd.load(req, context);
            var sndChannel:SoundChannel = new SoundChannel();
            sndChannel = snd.play(0, 9999);
        }

        private function render(e:Event):void {
            bytes.clear();
            SoundMixer.computeSpectrum(bytes, FFTswitch, 0);
            vol = bytes.readFloat();
            if(vol > .8)change();

            for (var i:int = 0; i < 100; i++) {
                vol = bytes.readFloat();
            }
        }

    }
}


internal class Particle {
    public var x1:Number;
    public var y1:Number;
    public var x0:Number;
    public var y0:Number;
    public var next:Particle;
}