forked from: forked from: forked from: 残像エフェクトつきサウンドビジュアライザ

by s8t1h12akj forked from forked from: forked from: 残像エフェクトつきサウンドビジュアライザ (diff: 3)
♥0 | Line 58 | Modified 2016-07-26 16:24:16 | MIT License
play

ActionScript3 source code

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

// forked from s8t1h12akj's forked from: forked from: 残像エフェクトつきサウンドビジュアライザ
// forked from s8t1h12akj's forked from: 残像エフェクトつきサウンドビジュアライザ
// forked from yun's 残像エフェクトつきサウンドビジュアライザ
// forked from yun's サウンドビジュアライザ
// forked from yun's カメラの動きにイージングを付ける
// forked from yun's カメラの動きを指定
// forked from yun's 3Dオブジェクトに動きを付ける
// forked from yun's シンプルな3Dオブジェクト
package {
    import flash.display.*;
    import flash.filters.*;
    import flash.geom.*;
    import flash.events.*;
    import flash.media.*;
    import flash.net.*;
    import org.papervision3d.materials.*;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.view.*;
    import org.papervision3d.core.effects.*;
    import org.papervision3d.core.effects.utils.*;
    import org.papervision3d.view.layer.*;
    
    public class Sample extends BasicView {
        
        private var soundChannel:SoundChannel;
        private var sphere1:Sphere;
        private var sphere2:Sphere;
        
        public function Sample():void {
            // 背景を黒に設定
            viewport.opaqueBackground = 0x000000;
            
            // エフェクトレイヤーを追加
            var bfx:BitmapEffectLayer = new BitmapEffectLayer( viewport, 465, 465 );
            bfx.addEffect( new BitmapLayerEffect( new BlurFilter( 16, 16, 5 ) ) );
            bfx.drawCommand = new BitmapDrawCommand( null, new ColorTransform( 1, 1, 1, 0.15 ), BlendMode.ADD );
            bfx.clippingPoint = new Point( 0, 0 );
            viewport.containerSprite.addLayer( bfx );
            
            // 球体を作成
            var material1:WireframeMaterial = new WireframeMaterial( 0xFF0000 );
            var material2:WireframeMaterial = new WireframeMaterial( 0x00CCFF );
            sphere1 = new Sphere( material1, 800, 20, 20 );
            sphere2 = new Sphere( material2, 800, 20, 20 );
            sphere1.x = 600;
            sphere2.x = -600;
            scene.addChild( sphere1 );
            scene.addChild( sphere2 );
            
            // エフェクトレイヤーに追加
            bfx.addDisplayObject3D( sphere1 );
            bfx.addDisplayObject3D( sphere2 );
                        
            // 音楽読み込み
            var sound:Sound = new Sound( new URLRequest( "http://kouetu.sakura.ne.jp/mp3_mujic/hakodate_wumen.mp3" ) );
            soundChannel = sound.play();            
            // レンダリング
            startRendering();
            addEventListener( Event.ENTER_FRAME, loop );
        }
        
        private function loop( e:Event ):void {
            // 音量取得
            var volume:Number = ( soundChannel.leftPeak + soundChannel.rightPeak ) / 2;
            
            // 球体のスケールを制御
            sphere1.scale -= 0.02;
            sphere2.scale -= 0.02;
            sphere1.scale = Math.max( volume, sphere1.scale );
            sphere2.scale = Math.max( volume, sphere2.scale );
            
            // 球面の回転を制御
            sphere1.rotationX += soundChannel.leftPeak * 5;
            sphere1.rotationY += soundChannel.rightPeak * 5;
            sphere2.rotationX += soundChannel.leftPeak * 10;
            sphere2.rotationY += soundChannel.rightPeak * 10;
            
            // カメラの位置を変更
            var rateX:Number = mouseX / stage.stageWidth;
            var targetX:Number = -5000 * ( rateX - 0.5 );
            camera.x += ( targetX - camera.x ) * 0.2;
            
            var rateY:Number = mouseY / stage.stageHeight;
            var targetY:Number = 5000 * ( rateY - 0.5 );
            camera.y += ( targetY - camera.y ) * 0.2;
        }
    }
}

Forked