Actionscript使用drawTriangles实现图像的扭曲

April 8, 2010 | tags flash flex actionscript 图像扭曲   | views
Comments 0
Actionscript的drawTriangles方法原来是为了三维的三角面准备的,我在实际项目中简单的用了下,用来简单的扭曲位图,效果还不错。下面写一个简单的例子,主要记用法,效果就不管了,呵呵。

demo

package 
{
import flash.display.BitmapData;
import flash.display.Shape;
import flash.display.Sprite;

public class DrawTrianglesDemo extends Sprite{

private var _sp:Shape;

public function DrawTrianglesDemo() {

var vertices:Vector.;
var indices:Vector.;
var uvtData:Vector.;

vertices = new Vector.(); //这里在这120×120的位图上定义了6个点
vertices.push(0, 0);
vertices.push(-10, 60); //这里如果是 vertices.push(0, 60);则左边不扭曲
vertices.push(0, 120);
vertices.push(120, 0);
vertices.push(130, 60); //这里如果是 vertices.push(120, 60);则右边不扭曲
vertices.push(120,120);

indices = new Vector.();//这里用之前的6个点将图形分成4个三角形
indices.push(0, 3, 4);
indices.push(0, 1, 4);
indices.push(1, 4, 5);
indices.push(1, 2, 5);

uvtData = new Vector.();//这里是定义6各点原来应在的位置
uvtData.push(0, 0);
uvtData.push(0, 0.5);
uvtData.push(0, 1);
uvtData.push(1, 0);
uvtData.push(1, 0.5);
uvtData.push(1, 1);

_sp = face.getChildAt(0) as Shape;
var myBitmapData:BitmapData = new BitmapData(_sp.width, _sp.height, true, 0xFFFFFF);
myBitmapData.draw(_sp);

_sp.graphics.clear();
_sp.graphics.beginBitmapFill(myBitmapData);
_sp.graphics.drawTriangles(vertices, indices, uvtData);
_sp.graphics.endFill();
}

}

}


    相关文章:



发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。