Spectrum Graph
package{
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import flash.ui.*;
import flash.geom.*;
import flash.filters.*;
import flash.media.*;
public class Main extends Sprite {
private var _spectrumBMP:BitmapData;
public function Main( )
{
_spectrumBMP = new BitmapData(256, 30, true, 0x00000000);
var bitmap:Bitmap = new Bitmap(_spectrumBMP);
bitmap.filters = [new DropShadowFilter(3, 45, 0, 1, 3, 2, .3, 3)];
addChild(bitmap);
}
public function update( ):void
{
// Get spectrum data
var spectrum:ByteArray = new ByteArray( );
SoundMixer.computeSpectrum(spectrum);
// Draw to bitmap
_spectrumBMP.fillRect(_spectrumBMP.rect, 0xff666666);
_spectrumBMP.fillRect(new Rectangle(1, 1, 254, 28),
0x00000000);
for(var i:int=0;i<256;i++) {
_spectrumBMP.setPixel32(i,
10 + spectrum.readFloat( ) * 10,
0xff000000);
}
for(var i:int=0;i<256;i++) {
_spectrumBMP.setPixel32(i,
20 + spectrum.readFloat( ) * 10,
0xff000000);
}
}
}
}
Related examples in the same category