当前位置: 主页 > 平面设计 > Flash AS实例教程:用纯AS制作火焰特效

Flash AS实例教程:用纯AS制作火焰特效

  • 2022-02-05
  • 来源/作者: PS.ONEGREEN.ORG    / 佚名    
  • 5 次浏览

  本文示例源代码或素材下载

  首先申明不是偶原创,偶只是把效果综合了一下。粒子变幻效果忘记是谁的了,知道出处的朋友请提醒,偶在以后补上。火焰瑞流效果是来自一位朋友的博客里面的摄像头火焰特效,也无处可考证出处,请知道的朋友提醒,偶以后补上。还有个返回无重复随机数组的函数在里面,是坛子里的朋友的,知道出处的朋友也请告知,呵呵呵...

  以下是关键原码和原始文件,感兴趣的朋友可以看看:Fire_ok.as:

/*
没啥好说的,拿去用吧:)
*/
class Fire_ok extends MovieClip
{
  var fireBmp, prevBmp, tempBmp, greyBmp, mtx, pnt, blurF, greyscaleCMF, fireCMF, dispMapF, webcam, fireBmpHolder, createEmptyMovieClip;
  var activityLevel_pb, wcGet ;
  function Fire_ok ()
  {
    super ();
    fireBmp = new flash.display.BitmapData (400, 400, false, 0);
    prevBmp = fireBmp.clone ();
    tempBmp = fireBmp.clone ();
    greyBmp = new flash.display.BitmapData (400, 400, false, 16743424);
    mtx = new flash.geom.Matrix ();
    pnt = new flash.geom.Point ();
    blurF = new flash.filters.BlurFilter (7, 7, 1);
    greyscaleCMF = new flash.filters.ColorMatrixFilter ([0.73, 0.83, 0.93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]);
    fireCMF = new flash.filters.ColorMatrixFilter ([0.8, 0.05, 0, 0, 0, 0, 0.65, 0, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1, 0]);
    dispMapF = new flash.filters.DisplacementMapFilter (tempBmp, pnt, 1, 2, 10, - 35, "clamp");
    /////////////////////////////////////////////////////
  }
  function configUI ()
  {
    fireBmpHolder = this.createEmptyMovieClip ("fireBmpHolder", 1);
    fireBmpHolder.attachBitmap (fireBmp, 1, "always", false);
    fireBmpHolder.blendMode = "add";
  }
  function onEnterFrame ()
  {
    tempBmp.copyPixels (prevBmp, prevBmp.rectangle, pnt);
    prevBmp.draw (webcam);
    if (tempBmp.getPixel (1, 1) < 2)
    {
      return (undefined);
    }
    tempBmp.draw (prevBmp, mtx, null, "difference");
    
    tempBmp.applyFilter (tempBmp, tempBmp.rectangle, pnt, greyscaleCMF);
    tempBmp.threshold (tempBmp, tempBmp.rectangle, pnt, ">", 1638400, 4289379174, 16711680, false);
    tempBmp.applyFilter (tempBmp, tempBmp.rectangle, pnt, blurF);
    fireBmp.draw (tempBmp, mtx, null, "add");
    
    tempBmp.perlinNoise (13, 10, 1, random (100) , false, true, 3, false);
    tempBmp.draw (greyBmp, mtx, null, "darken");
    
    fireBmp.applyFilter (fireBmp, fireBmp.rectangle, pnt, dispMapF);
    fireBmp.applyFilter (fireBmp, fireBmp.rectangle, pnt, fireCMF);
  }
  static var CLASS_REF = Fire_ok;
  static var LINKAGE_ID = "Fire_ok";
}