Just wondering do you have the formulas written more clear in languages like actionscript.
I am trying to do the effects in flash now.
It is very hard i think to read the bash script but it is possible. I already made two of the stuff into actionscript
I am not completely sure if I written them correct or not thats why I am wondering if there are those fx scripts written in other languages.
Code: Select all
public function pinbarrel(source:BitmapData,ax:Number = 1,bx:Number = 0,cx:Number = 0,dx:Number = 0,ex:Number = 0,ay:Number = 1 ,by:Number = 0,cy:Number = 0,dy:Number = 0,ey:Number = 0):BitmapData {
var newimage:BitmapData = new BitmapData(source.width, source.height);
var width:int = source.width;
var height:int = source.height;
var w2:Number = width/2;
var h2:Number = height/2;
var xc:int = (width / 2) - 0.5;
var yc:int = (height / 2) - 0.5;
var sf:Number;
if (w2 > h2) {
sf = h2;
} else {
sf = w2;
}
for (var i:int = 0; i < source.width; i++) {
var xd:Number = i - xc;
for (var j:int = 0; j < source.height; j++) {
var yd:Number = j - yc;
var rd:Number = Math.sqrt(xd*xd + yd*yd)/sf;
var rrd:Number = rd*rd;
var rrrd:Number = rd*rd*rd;
var rrrrd:Number = rd*rd*rd*rd;
var ctermx:Number = ax + bx*rd + cx*rrd + dx*rrrd + ex*rrrrd;
var ctermy:Number = ay + by*rd + cy*rrd + dy*rrrd + ey*rrrrd;
var fdx:Number = ctermx;
var fdy:Number = ctermy;
var xs:Number = fdx*xd+xc;
var ys:Number = fdy*yd+yc;
newimage.setPixel32(i,j,source.getPixel32(xs,ys));
}
}
return newimage;
//"xd=(i-$xc); yd=(j-$yc); $rd $rterm $fdx $fdy xs=fdx*xd+$xc; ys=fdy*yd+$yc; u.p{xs,ys}"
}
public function barreleffect(source:BitmapData, distortamount:Number):BitmapData {
var newimage:BitmapData = new BitmapData(source.width, source.height);
// Distortamount should be range -1.0 to 1.0
var d:Number = distortamount;
var a:Number = 1+d
var b:Number = -d
var width:int = source.width;
var height:int = source.height;
var w2:Number = width/2;
var h2:Number = height/2;
var sf:Number =(w2+h2)/2;
var xc:Number = w2;
var yc:Number = h2;
for (var i:int = 0; i < source.width; i++) {
var xd:Number = i - xc;
for (var j:int = 0; j < source.height; j++) {
var yd:Number = j - yc;
var rd:Number = Math.sqrt(xd*xd+yd*yd)/sf;
var ys:Number = (yd/(a+b*rd))+yc;
newimage.setPixel32(i,j,source.getPixel32(i,ys));
}
}
return newimage;
}