- 最后登录
- 2013-6-5
- 注册时间
- 2012-2-13
- 阅读权限
- 90
- 积分
- 28981
- 纳金币
- 30927
- 精华
- 3
|
package {
import flash.display.Sprite;
import flash.media.*;
import flash.net.*;
import flash.events.*;
import flash.geom.Vector3D;
import flare.basic.Scene3D;
import flare.basic.Viewer3D;
import flare.core.Lines3D;
import flare.core.Camera3D;
import flash.utils.ByteArray;
import flash.text.*;
[SWF(width=800,height=600,frameRate=20)]
public class soundWave extends Sprite {
var scene:Scene3D;
var lineArr1:Array;
var lineArr2:Array;
var tempPtArr:Array;
var moArr:Array;
var ptArr:Array;
var soundByte:ByteArray;
var sound:Sound;
var soundCh:SoundChannel;
public function soundWave() {
scene=new Viewer3D(this);
scene.camera=new Camera3D();
scene.camera.setPosition(-100,130,-200);
scene.camera.lookAt(0,0,0);
init();
var txt:TextField=new TextField();
var txtFormat:TextFormat=new TextFormat(null,20,0xff0000);
txt.text="按下鼠标左键 拖动,可以旋转视角";
txt.setTextFormat(txtFormat);
txt.autoSize=TextFieldAutoSize.LEFT;
addChild(txt);
}
private function init(){
buildMesh();
}
private function buildMesh(){
ptArr=new Array();
for(var i=0;i<128;i++){
var temptArr:Array=new Array();
for(var a=0;a<32;a++){
var pt:Vector3D=new Vector3D(i*5-160,0,a*5-80);
temptArr.push(pt);
}
ptArr.push(temptArr);
}
buildLines();
moArr=new Array();
for(var v=0;v<32;v++){
var moPt:Vector3D=ptArr[0][v].clone();
moArr.push(moPt);
}
}
private function buildLines(){
lineArr1=new Array();
lineArr2=new Array ();
for(var i=0;i<128;i++){
var line1ines3D=new Lines3D();
line1.lineStyle(1,0x33ffff);
line1.moveTo(ptArr[0].x,ptArr[0].y,ptArr[0].z);
for(var a=0;a<32;a++){
line1.lineTo(ptArr[a].x,ptArr[a].y,ptArr[a].z)
}
scene.addChild(line1);
lineArr1.push(line1);
}
for(var p=0;p<32;p++){
var line2ines3D=new Lines3D();
line2.lineStyle(1,0x33ffff);
line2.moveTo(ptArr[0][p].x,ptArr[0][p].y,ptArr[0][p].z);
for(var u=0;u<128;u++){
line2.lineTo(ptArr[p].x,ptArr[p].y,ptArr[p].z);
}
scene.addChild(line2);
lineArr2.push(line2);
}
playSound();
//buildLines2();
}
private function buildLines2(){
for(var i=0;i<128;i++){
var line1ines3D=new Lines3D();
line1.lineStyle(1,0x33ffff);
line1.moveTo(ptArr[0].x,ptArr[0].y,ptArr[0].z);
for(var a=0;a<32;a++){
line1.lineTo(ptArr[a].x,ptArr[a].y,ptArr[a].z)
}
scene.addChild(line1);
}
for(var p=0;p<32;p++){
var line2ines3D=new Lines3D();
line2.lineStyle(1,0x33ffff);
line2.moveTo(ptArr[0][p].x,ptArr[0][p].y,ptArr[0][p].z);
for(var u=0;u<128;u++){
line2.lineTo(ptArr[p].x,ptArr[p].y,ptArr[p].z);
}
scene.addChild(line2);
}
}
private function playSound(){
sound=new Sound(new URLRequest("Kalimba.mp3"));
soundCh=sound.play();
soundByte=new ByteArray();
stage.addEventListener(Event.ENTER_FRAME,onFrame);
}
private function onFrame(e){
SoundMixer.computeSpec***m(soundByte);
var tempPtArr:Array=new Array ();
for(var i=0;i<32;i++){
var pt:Vector3D=new Vector3D();
pt.x=-160;
pt.z=i*5-80;
pt.y=Math.abs(soundByte.readFloat())*50;
tempPtArr.push(pt);
}
for(var c=0;c<128;c++){
for(var w=0;w<32;w++){
ptArr[c][w].x+=5;
}
}
ptArr.unshift(tempPtArr);
ptArr.pop();
for(var d=0;d<128;d++){
lineArr1[d].clear();
}
for(var f=0;f<32;f++){
lineArr2[f].clear();
}
for(var h=0;h<32;h++){
lineArr2[h].moveTo(ptArr[0][h].x,ptArr[0][h].y,ptArr[0][h].z);
for(var j=0;j<128;j++){
lineArr2[h].lineTo(ptArr[j][h].x,ptArr[j][h].y,ptArr[j][h].z);
}
}
for(var k=0;k<128;k++){
lineArr1[k].moveTo(ptArr[k][0].x,ptArr[k][0].y,ptArr[k][0].z);
for(var l=0;l<32;l++){
lineArr1[k].lineTo(ptArr[k][l].x,ptArr[k][l].y,ptArr[k][l].z);
}
}
}
}
}
http://1552951214.sinaapp.com/soundWave.html 在线演示地址 |
|