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
bitmapData2.setPixel(i,j,bitmapData1.getPixel(point.x,point.y));
}
}
}
return bitmapData2;
}
}
}