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

soundtest8 - Trash

色って難しい
もうわけかわらん状態
pixelでどうにかして
Get Adobe Flash player
by gaina 06 Jul 2010
/**
 * Copyright gaina ( http://wonderfl.net/user/gaina )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/g27f
 */

//色って難しい
//もうわけかわらん状態
//pixelでどうにかして

package 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.filters.BlurFilter;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundLoaderContext;
    import flash.media.SoundMixer;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;
    import org.papervision3d.core.effects.BitmapLayerEffect;
    import org.papervision3d.core.effects.utils.BitmapDrawCommand;
    import org.papervision3d.core.geom.Pixels
    import org.papervision3d.core.geom.renderables.Pixel3D;
    import org.papervision3d.materials.BitmapColorMaterial;
    import org.papervision3d.objects.primitives.Sphere;
    import org.papervision3d.view.BasicView;
    import org.papervision3d.view.layer.BitmapEffectLayer;
    
    
    [SWF(width=465,height=465,backgroundColor=0x000000)]
    public class Main extends BasicView
    {
        private var NUM:int = 256;
        private var rot:Number = 0;
        
        private var snd:Sound;
        private var sndChannel:SoundChannel;
        
        private var LRarr:Array = [];
        
        private var FFTswitcher:Boolean = false;
        private var matrix:Matrix;
        private var canvas:Bitmap;
        private var bmpData:BitmapData;
        
        
        public function Main():void 
        {
            Wonderfl.capture_delay(2);
            playSound("http://www.takasumi-nagai.com/soundfiles/sound001.mp3");
            camera.zoom = 2 ;
        }
        
        private function playSound(sndUrl:String):void
        {
            snd = new Sound();
            var context:SoundLoaderContext = new SoundLoaderContext(10,true);
            var req:URLRequest = new URLRequest(sndUrl);
            snd.load(req, context);
            snd.addEventListener(Event.COMPLETE, onComp);
        }
        
        private function onComp(e:Event):void 
        {
            graphics.beginFill(0x000000);
            graphics.drawRect(0, 0, 465, 465);
            graphics.endFill();
            
            sndChannel=new SoundChannel();
            sndChannel = snd.play(0, 5);
            LRarr = draw();
            startRendering();
            addEventListener(Event.ENTER_FRAME, loop);
            stage.addEventListener(MouseEvent.CLICK, FFTSwitch);
            bmpData = new BitmapData(465 / 4, 465 / 4, false, 0x000000);
            canvas = new Bitmap(bmpData, "never", true);
            canvas.scaleX = canvas.scaleY = 4;
            canvas.smoothing = true;
            canvas.blendMode = BlendMode.ADD;
            addChild(canvas);
            matrix = new Matrix(0.25, 0, 0, 0.25);
        }
        
        private function FFTSwitch(e:MouseEvent):void 
        {
            if (FFTswitcher) { FFTswitcher = false } else { FFTswitcher = true; }
        }
        
        private function loop(event:Event):void 
        {
            bmpData.fillRect(bmpData.rect, 0x000000);
            bmpData.draw(viewport, matrix);
            
            rot += 1%360;
            
            camera.x = 500 * Math.sin(rot * Math.PI / 180);
            camera.z = 500 * Math.cos(rot * Math.PI / 180);
            camera.y = 500 * Math.cos(rot * Math.PI / 180);
            camera.zoom += ( 50 - camera.zoom) / 10;
            
            var bytes:ByteArray = new ByteArray();
            SoundMixer.computeSpectrum(bytes, FFTswitcher, 0);
            
            for (var n:int = 0; n < 2; n++)
            {
                var soundArray:Array = LRarr[n];
                for (var i:int = 0; i < 256; i++)
                {
                    var px:Pixel3D = new Pixel3D(0xFF000000);
                    px = soundArray[i];
                    var data:Number = bytes.readFloat();
                    
                    if (i == 0)
                    {
                        if (data>0.35)
                        {
                            camera.zoom = 0;
                        }
                    }
                    
                    if (10 < i <50)
                    {
                        if (data>0.3)
                        {
                            rot += 10;
                            //bmpData.colorTransform(bmpData.rect, new ColorTransform(1, 1, 1, 1, 1, 0, 0, 0));
                        }
                    }
                    
                    
                }
            }
        }
        
        private function draw():Array
        {
            var master_arr:Array = [];
            
            var _effect:BitmapEffectLayer = new BitmapEffectLayer(viewport, 465, 465);
             _effect.addEffect(new BitmapLayerEffect(new BlurFilter(3, 2, 1)));
            
            _effect.drawCommand = new BitmapDrawCommand(null, null, BlendMode.ADD);
            viewport.containerSprite.addLayer(_effect);
            
            var pxs:Pixels = new Pixels(_effect);
            scene.addChild(pxs);
            
            for (var n:int = 0; n < 2; n++)
            {
                var lr_arr:Array = [];
                for (var i:int = 0; i < NUM; i++)
                {
                    var xx:Number = Math.random() * 1000 - 500;
                    var yy:Number = Math.random() * 1000 - 500;
                    var zz:Number = Math.random() * 1000 - 500;
                    
                    if (n == 0)
                    {
                        var px01:Pixel3D = new Pixel3D(0xFFffffff, xx, yy, zz);
                        pxs.addPixel3D(px01);
                        lr_arr.push(px01);
                    }
                    else
                    {
                        var px02:Pixel3D = new Pixel3D(0xFFffffff, xx, yy, zz);
                        //var px02:Pixel3D = new Pixel3D(0xFFff00ff, xx, yy, zz);
                        pxs.addPixel3D(px02);
                        lr_arr.push(px02);
                    }
                }
                master_arr.push(lr_arr);
            }
            return master_arr;
        }
        
    }
    
}