サウンドビジュアライザ
/**
* Copyright yun ( http://wonderfl.net/user/yun )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/5YQm
*/
// forked from yun's カメラの動きにイージングを付ける
// forked from yun's カメラの動きを指定
// forked from yun's 3Dオブジェクトに動きを付ける
// forked from yun's シンプルな3Dオブジェクト
package {
import flash.events.*;
import flash.media.*;
import flash.net.*;
import org.papervision3d.materials.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.view.*;
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 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 );
// 音楽読み込み
var sound:Sound = new Sound( new URLRequest( "http://mutast.heteml.jp/works/music/music.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;
}
}
}