AS3 Papervision + Sound Visualizer + Line3D + Tweener - Part 2 FF07
So here’s my Flash Forward inspired piece!
Once again used Andy’s great Line3D class and gave it a Flash Forward 07 twist.
import flash.events.Event;
import flash.display.*;
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.utils.ByteArray;
import caurina.transitions.Tweener;
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.*;
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.materials.*;
public class Hydro3D extends Sprite {
private static const LOOP:String = “../flashassets/mp3/jens_buchert.mp3″;
private const STAGE_WIDTH :Number = 600;
private const STAGE_HEIGHT :Number = 300;
private const ANIMATION_TIME :Number = 1;
private const ANIMATION_TYPE :String = “easeoutquad”;
private const MULT :int = 10;
private var controlPoints :Array;
private var itemArray :Array;
private var trailArray :Array;
private var currTrailArray :Array;
private var lineArray :Array;
private var count :int = 0;
private var container :Sprite;
private var scene :MovieScene3D;
private var camera :Camera3D;
private var sc :SoundChannel;
private var s :Sound;
private var lines :Line3D;
public function Hydro3D():void {
controlPoints = [];
itemArray = [];
trailArray = [];
currTrailArray = [];
lineArray = [];
s = new Sound();
s.load(new URLRequest(LOOP));
sc = s.play(0, 1000);
//container
container = new Sprite();
container.cacheAsBitmap = true;
addChild( container );
container.x = STAGE_WIDTH/2;
container.y = STAGE_HEIGHT/2;
//scene
scene = new MovieScene3D( container );
//camera
camera = new Camera3D();
camera.z = -200;
addEventListener( Event.ENTER_FRAME, onEnterFrame );
}
private function onEnterFrame( event: Event ):void {
camera.x +=((container.mouseX*10) - camera.x) * 0.005;
camera.y +=((container.mouseY*10) - camera.y) * 0.005;
var bytes:ByteArray = new ByteArray();
SoundMixer.computeSpectrum(bytes, false, 0);
var amp:Number = ((sc.leftPeak + sc.rightPeak)/2);
lineArray[count] = new Line3D([new Vertex3D(-128, 0, -(count * MULT))], rgbToHex(count/4, count/6, count), 1, 1);
scene.addChild(lineArray[count]);
for(var i:int = 0; i < 256; i++){
var v:Vertex3D = new Vertex3D((i*2) - 128, bytes.readFloat() * 300, -(count * MULT));
lineArray[count].addVertex(v);
}
Tweener.addTween(lineArray[count], {
alpha:0,
time:ANIMATION_TIME,
transition:ANIMATION_TYPE,
onComplete:removeLine,
onCompleteParams:[lineArray[count]]
});
scene.renderCamera( camera );
count = (count < 50) ? count + 1 : 0;
};
private function removeLine(l:Line3D = null):void{
scene.removeChild(l);
}
public function rgbToHex(uR:uint, uG:uint, uB:uint):int{
var uColor:uint;
uColor = (uR & 255) << 16;
uColor += (uG & 255) << 8;
uColor += (uB & 255);
return uColor;
}
}
}
I didn’t do anything with the amplitude but I left it in there if you decide you want to play with it. It’s somewhat processor intensive. I wish external mp3’s would loop. You’d think Adobe would have addressed that by now. Because of that, you’d want to attach it from your library, but I think it’s ok for testing. Helps you find a good loop that gives you good results when playing with a visualizer. Just overwrite the mp3 file or switch the path.
Once again the loop I’m using:

The music is the song “Mélange Eléctrique” from Jens Buchert’s album Spa Lounge. Great downtempo album.
September 21st, 2007 at 8:25 am
Excellent demo and great music choice. Look forward to meet you here in Boston.
October 1st, 2007 at 6:45 am
Sorry I can’t see anything! Windows XP, tried both IE7 and FireFox, Flash Player 9,0,47,0
October 1st, 2007 at 9:18 am
There is a bug in the flash player with IE7. The onComplete loading event doesn’t fire. I was lazy and forgot to update the loader in this example using only an onEnterframe event to determine progress. If you remove the complete event and do a gotoAndPlay(2) then you should be fine. I plan on posting an example of that soon, but it’s easy to find and is a known issue.
October 1st, 2007 at 10:46 am
[...] Donovan Adams: 1, 2, 3, 4, 5 [...]
October 9th, 2007 at 10:59 am
[...] Donovan Adams also has a demo using PV3D (and its new Line3D) and Tweener for audio visualization, although in a different way. [...]
July 22nd, 2008 at 9:01 am
[...] Donovan Adams also has a demo using PV3D (and its new Line3D) and Tweener for audio visualization, although in a different way. [...]