一聚教程网:一个值得你收藏的教程网站

热门教程

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

时间:2022-07-02 17:02:27 编辑:袖梨 来源:一聚教程网

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     for (var j:int=pointCenter.y-r; j      if (Point.distance(new Point(i,j),pointCenter)       point=getSpherizePoint(new Point(i,j));
      bitmapData2.setPixel(i,j,bitmapData1.getPixel(point.x,point.y));
     }
    }
   }
   return bitmapData2;
  }
}
}

热门栏目