当前位置:软件学习 > Flash >>

flash as 3.0 模仿ps球面化滤镜源码

package {
import flash.geom.*;
import flash.display.*;
public class Spherize {
  private var r:Number;
  private var h:Number;
  private var pointCenter:Point;
  private var isSmoothing:Boolean;
  public function Spherize(r:Number,h:Number,pointCenter:Point,isSmoothing) {
   init(r,h,pointCenter,isSmoothing);
  }
  public function init(r:Number,h:Number,pointCenter:Point,isSmoothing):void {
   this.r=r;
   this.h=h;
   this.pointCenter=pointCenter;
   this.isSmoothing=isSmoothing;
  }
  public function getSpherizePoint(point:Point):Point {
   var R:Number=(r*r+h*h)/(2*h);
   var l:Number=Point.distance(point,pointCenter);
   return Point.interpolate(Point.interpolate(point,pointCenter,r / l),pointCenter,Math.asin(l / R) / Math.acos((R - h) / R));
  }
  public function getSpherizeBitmapData(bitmapData:BitmapData):BitmapData {
   var bitmapData1:BitmapData=bitmapData.clone();
   var bitmapData2:BitmapData=bitmapData.clone();
   var point:Point=new Point();
   for (var i:int=pointCenter.x-r; i<pointCenter.x+r; i++) {
    for (var j:int=pointCenter.y-r; j<pointCenter.y+r; j++) {
     if (Point.distance(new Point(i,j),pointCenter)<r) {
      point=getSpherizePoint(new Point(i,j));
      bitmapData2.setPixel(i,j,bitmapData1.getPixel(point.x,point.y));
     }
    }
   }
   return bitmapData2;
  }
}
}

补充:flash教程,As3.0
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,