当前位置:七道奇文章资讯设计学堂Flash设计
日期:2009-04-04 00:51:00  来源:本站整理

<b>Flash ActionScript制作真实的火焰</b>[Flash设计]

赞助商链接



  本文“<b>Flash ActionScript制作真实的火焰</b>[Flash设计]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
效果以下:

点击这里下载源文件

  主要代码:

import flash.display.*;
import flash.filters.*;
import flash.geom.*;
import de.popforge.bitmap.Shape;
Shape.setContainer( this.createEmptyMovieClip( 'shapes', 10000 ) );
//-- get blue circle as a bitmap
var blueSpotClip: MovieClip = attachMovie( "blueSpot", "blueSpotClip", 0 );
var clipBounds: Object = blueSpotClip.getBounds();
var blueSpot: BitmapData = new BitmapData( clipBounds.xMax, clipBounds.yMax, true, 0 );
blueSpot.draw( blueSpotClip, new Matrix() );
blueSpotClip.removeMovieClip();
//-- involved bitmaps
var source: BitmapData = new BitmapData( 256, 256, false, 0 );
var output: BitmapData = new BitmapData( 256, 256, false, 0 );
var buffer: BitmapData = new BitmapData( 256, 256, false, 0 );
var bounds: Rectangle = new Rectangle( 0, 0, 256, 256 );
var origin: Point = new Point();
var matrix: Matrix = new Matrix();
//-- creating a gradient with fire colors
import de.popforge.bitmap.Gradient;
var firePalette: Array = Gradient.fillArray
(
 [ 0, 0xA20000, 0xFFF122, 0xFFFFFF, 0xF8FF1B, 0xC53C05, 0 ],
 [ 0, 50, 50, 100, 75, 25, 0 ],
 [ 0, 64, 132, 186, 220, 250, 255 ]
);
//-- Filter to let the flame grow
var flame: ConvolutionFilter = new ConvolutionFilter( 3, 3, null, 2.7, -2 );
attachBitmap( output, 0, false, false );
var ms: Number = getTimer();
var frame: Number = 0;
onMouseMove = function()
{
 //-- create burning area
 var mouse: Point = new Point( _xmouse - clipBounds.xMax/2, _ymouse - clipBounds.yMax/2 );
 source.copyPixels( blueSpot, new Rectangle( 0, 0, clipBounds.xMax, clipBounds.yMax ), mouse );
}
onEnterFrame = function()
{
 //-- create burning area
 var mouse: Point = new Point( _xmouse - clipBounds.xMax/2, _ymouse - clipBounds.yMax/2 );
 source.copyPixels( blueSpot, new Rectangle( 0, 0, clipBounds.xMax, clipBounds.yMax ), mouse );
 //-- the flames matrix with some randoms to expand the flame sidewards
 var flameMatrix: Array = [ 0, 0, 0, 0, 0.2, 0, 0, 1.6, 0 ];
 flameMatrix[3] = Math.random() * .001;
 flameMatrix[5] = Math.random() * .001;
 flameMatrix[6] = .4 + Math.random() * .1;
 flameMatrix[8] = .4 + Math.random() * .1;
 flame.matrix = flameMatrix;
 //-- applying the filter 3 times to increase the flame speed
 //-- compute the affected region by "generateFilterRect", "getColorBoundsRect"
 var area: Rectangle = source.generateFilterRect( source.getColorBoundsRect( 0xFF, 0, false ), flame );
 source.applyFilter( source, area, area.topLeft, flame );
 area = source.generateFilterRect( area, flame );
 source.applyFilter( source, area, area.topLeft, flame );
 area = source.generateFilterRect( area, flame );
 source.applyFilter( source, area, area.topLeft, flame );
 //-- remap the the flame bitmap with fire colors
 output.paletteMap( source, area, area.topLeft, null, null, firePalette );
 //-- fps
 if( getTimer() - 1000 > ms )
 {
  ms = getTimer();
  fps = frame;
  fpsDisplay.text = fps.toString();
  frame = 0;
 }
 else
 {
  frame++;
 }
}
var mouseDown: Boolean = false;
onMouseDown = function()
{
 mouseDown = true;
}
onMouseUp = function()
{
 onEnterFrame();
 mouseDown = false;
}
createTextField( "fpsDisplay", 99, 0, 0, 60, 20 );
fpsDisplay.textColor = 0xffffff;
fpsDisplay.selectable = false;

对应的AS代码:Gradient.as

import de.popforge.bitmap.Shape;

import flash.display.BitmapData;
import flash.geom.ColorTransform;
import flash.geom.Matrix;

class de.popforge.bitmap.Gradient
{
 public static function createXYGradient(): BitmapData
 {
  /*
   * get canvas
   */
  var g: Shape = Shape.get();
  
  if( g == null )
  {
   return null;
  }
 
  var xyGradient: BitmapData = new BitmapData( 256, 256, false, 0 );
 
  var matrix: Matrix = new Matrix();
 
  /*
   * create y as blue colorvalues
   */
 
  matrix.createGradientBox( 256, 256, Math.PI/2, 0, 0 );
 
  g.beginGradientFill( 'linear', [ 0, 0x0000ff ], [ 100, 100 ], [ 0, 0xff ], matrix );
  g.moveTo( 0, 0 );
  g.lineTo( 256, 0 );
  g.lineTo( 256, 256 );
  g.lineTo( 0, 256 );
  g.lineTo( 0, 0 );
  g.endFill();
 
  matrix.identity();
  xyGradient.draw( g, matrix );
 
  g.clear();
 
  /*
   * create x as green colorvalues
   */
 
  matrix.createGradientBox( 256, 256, 0, 0, 0 );
 
  g.beginGradientFill( 'linear', [ 0, 0x00ff00 ], [ 100, 100 ], [ 0, 0xff ], matrix );
  g.moveTo( 0, 0 );
  g.lineTo( 256, 0 );
  g.lineTo( 256, 256 );
  g.lineTo( 0, 256 );
  g.lineTo( 0, 0 );
  g.endFill();
 
  matrix.identity();
  xyGradient.draw( g, matrix, null, 'add' );
 
  g.removeMovieClip();
 
  return xyGradient;
 }
 
 public static function createDisplacementMapFromMidMap( midmap: BitmapData ): BitmapData
 {
  var displace: BitmapData = createXYGradient();
 
  if( displace == null )
  {
   return null;
  }
 
  var colorTransform: ColorTransform = new ColorTransform();
  var m: Matrix = new Matrix();
  colorTransform.greenMultiplier = .5;
  colorTransform.blueMultiplier = .5;
  displace.draw( displace, m, colorTransform );
  colorTransform.greenOffset = 128;
  colorTransform.blueOffset = 128;
  displace.draw( midmap, m, colorTransform, 'difference' );
 
  return displace;
 }
 
 /*
  * returns an array with 32bit colorvalues
  * usefull to remap a bitmap using 'paletteMap'
  */
 
 public static function fillArray( colors: Array, alphas: Array, ratios: Array ): Array
 {
  var g: Shape = Shape.get();
 
  if( g == null )
  {
   return null;
  }
 
  var array: Array = new Array;
 
  var m: Matrix = new Matrix();
 
  m.a = m.d = .15625;
  m.b = m.c = 0;
  m.tx = m.ty = 128;
 
  g.beginGradientFill( 'linear', colors, alphas, ratios, m );
  g.moveTo( 0, 0 );
  g.lineTo( 256, 0 );
  g.lineTo( 256, 1 );
  g.lineTo( 0, 1 );
  g.lineTo( 0, 0 );
  g.endFill();
 
  var bmp: BitmapData = new BitmapData( 256, 1, true, 0 );
 
  m.identity();
 
  bmp.draw( g, m );
 
  g.removeMovieClip();
 
  var x: Number = 256;
 
  while( --x > -1 )
  {
   array[x] = bmp.getPixel32( x, 0 );
  }
 
  return array;
 }
}

shap.as

import flash.display.BitmapData;
class de.popforge.bitmap.Shape extends MovieClip
{
 static var id: String = '__Packages.de.popforge.bitmap.Shape';
 
 static private var container: MovieClip;
 
 static public function setContainer( container: MovieClip ): Void
 {
  Shape.container = container;
  Object.registerClass( id, Shape );
 }
 
 static public function get(): Shape
 {
  if( container == undefined )
  {
   trace( 'ERROR: No container is defined. Call Shape.setContainer( timeline: MovieClip );' );
   return null;
  }
 
  var d: Number = container.getNextHighestDepth();
 
  return Shape( container.attachMovie( id, d.toString(), d ) );
 }
 
 public function rasterize( target: BitmapData ): Void
 {
  target.draw( this );
 }
}


  以上是“<b>Flash ActionScript制作真实的火焰</b>[Flash设计]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
  • <b>hosts是什么 hosts文件在什么位置 若何改正hosts</b>
  • <b>在 Windows 8 中手动安装语言包</b>
  • <b>五个常见 PHP数据库问题</b>
  • Windows中Alt键的12个高效快速的利用本领介绍
  • <b>MySQL ORDER BY 的实现解析</b>
  • <b>详解MySQL存储历程参数有三种范例(in、out、inout)</b>
  • <b>Win8系统恢复出来经典的开始菜单的办法</b>
  • <b>Win8系统花屏怎么办 Win8系统花屏的办理办法</b>
  • <b>Windows 7系统下无线网卡安装</b>
  • <b>为什么 Linux不需求碎片整理</b>
  • <b>Windows 8中删除账户的几种办法(图)</b>
  • <b>教你如安在win7下配置路由器</b>
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .