燃烧吧火焰

      做生活 2007-7-17 15:11

主要使用了BitmapData,Matrix,BlurFilter,graphics,其中有一个tempc=(255-i) << 16 ^ i << 8 ^ 0不用理会,只是产生个颜色列表,产生颜色的方法很多,实在不行可以手写个array调用,其他都是帮助中简单脚本。
例子如下:

代码如下:

package {
  import flash.display.Sprite;
  import flash.media.Sound;
  import flash.media.SoundMixer;
  import flash.utils.ByteArray;
  import flash.events.Event;
  import flash.net.URLRequest;
  import flash.display.Shape;
  import flash.display.Graphics;
  import flash.display.Bitmap;
  import flash.display.BitmapData;
  import flash.geom.Matrix;
  import flash.geom.Point;
  import flash.geom.Rectangle;
  import flash.filters.BitmapFilterQuality;
  import flash.filters.BlurFilter;
  public class wave extends Sprite {
    var sd:Sound = new Sound();
    var ba:ByteArray = new ByteArray();
    var wm:Shape=new Shape();
    var trans:Shape=new Shape();
    var bmp:BitmapData = new BitmapData(400, 500, false, 0x000000);
    var buffer:BitmapData = new BitmapData(400, 500, false, 0x000000);
    var blur:BlurFilter = new BlurFilter(10,10,2);
    var rect:Rectangle = new Rectangle(0, 0, 400, 500);
    var pt:Point = new Point(0, 0);
    var stagepic:Bitmap;
    var trans_m:Matrix=new Matrix(1.001,0.002,0.002,0.99,-0.01,-5);
    public function wave() {
      sd.load(new URLRequest("http://blog.5d.cn/02.mp3"));
      sd.play(0,1000);
      trans.graphics.beginFill(0x0000000,0.08);
      trans.graphics.drawRoundRect(0, 0, 400, 500, 0);
      trans.graphics.endFill();
      stagepic =new Bitmap(bmp);
      addChild(stagepic);
      addEventListener(Event.ENTER_FRAME,onEnterFrame);
    }
    private function onEnterFrame(event:Event):void {
      SoundMixer.computeSpectrum(ba,true,0);
      wm.graphics.clear();
      for (var i:int=0; i < 512; i++) {
        var tempc=(255-i) << 16 ^ i << 8 ^ 0;
        var tempj=ba.readFloat()*150;
        wm.graphics.lineStyle(6,tempc,0.3);
        if (i<255) {
          wm.graphics.moveTo(200,450-i);
          wm.graphics.lineTo(200-tempj,450-i);
        } else {
          wm.graphics.moveTo(200,706-i);
          wm.graphics.lineTo(200+tempj,706-i);
        }
      }
      bmp.draw(trans, null, null, "multiply");
      bmp.draw(wm, null, null, "add");
      buffer.draw(bmp);
      buffer.applyFilter(buffer, rect, pt, blur);
      bmp.draw(buffer,trans_m);
    }
  }
}

标签集:TAGS:flash example as3
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}