Sine Distort
Distorts an image using sine.
Source
https://github.com/amsqr/Chromanin.js
Notes
This does not work the same as the code it was made from.
The way the edges are handled is different...might look at it later, but probably not
Still, makes some cool looks.
Code
Configuration
Configuration.AddEditBox("_dx", "dx", "", 0.100000001490116);
Configuration.AddEditBox("_dy", "dy", "", 0.125);
Configuration.AddEditBox("_depthX", "depthX", "", 25);
Configuration.AddEditBox("_depthY", "depthY", "", 20);
Execution
var image = Document.RasterImage;
var clone = Document.Duplicate();
clone = clone.RasterImage;
var w = image.sizeX;
var h = image.sizeY;
function getBilerpixel(l, x, y) {
var corner = [];
var xi, yi, xip, xip1;
var yip, yip1;
xi = ~~x;
yi = ~~y;
xip = Math.max(Math.min(xi , w-1),0);
xip1 = Math.max(Math.min(xi + 1,w-1),0) ;
yip1 = Math.max(Math.min(yi + 1, h-1),0);
yip = Math.max(Math.min(yi , h-1),0);
corner[0] = l.GetPixel(xip,yip,0,0);//this.layers[l].data32[xip + yip];
corner[1] = l.GetPixel(xip1,yip,0,0);//this.layers[l].data32[xip1 + yip];
corner[2] = l.GetPixel(xip,yip1,0,0);//this.layers[l].data32[xip + yip1];
corner[3] = l.GetPixel(xip1,yip1,0,0);//this.layers[l].data32[xip1 + yip1];
return cosineInterpolate(corner, (x - xi), (y - yi));
}
function cosineInterpolate(v, x, y) {
var f1, f2, mf1, mf2, g0, g1, g2, g3;
var color,r,g,b;
mf1 = (1 - Math.cos(x * Math.PI)) * 0.5;
mf2 = (1 - Math.cos(y * Math.PI)) * 0.5;
var f1 = 1 - mf1;
var f2 = 1 - mf2;
var g0 = f1 * f2;
var g1 = mf1 * f2;
var g2 = f1 * mf2;
var g3 = mf1 * mf2;
color = ((v[0] & 255) * g0 + (v[1] & 255) * g1 + (v[2] & 255) * g2 + (v[3] & 255) * g3);
color = color | ((((v[0] >> 8 & 255) * g0 + (v[1] >> 8 & 255) * g1 + (v[2] >> 8 & 255) * g2 + (v[3] >> 8 & 255) * g3) & 255) << 8);
color = color | ((((v[0] >> 16 & 255) * g0 + (v[1] >> 16 & 255) * g1 + (v[2] >> 16 & 255) * g2 + (v[3] >> 16 & 255) * g3) & 255) << 16);
color = color | ((((v[0] >> 24 & 255) * g0 + (v[1] >> 24 & 255) * g1 + (v[2] >> 24 & 255) * g2 + (v[3] >> 24 & 255) * g3) & 255) << 24);
return color;
}
var dx=Configuration._dx;
var dy=Configuration._dy;
var depthX=Configuration._depthX;
var depthY=Configuration._depthY;
var lookupX=[],lookupY=[];
for(var x=0;x<w;x++){
lookupX[x]=Math.sin(dy * x) * depthY;
}
for(var y=0;y<h;y++){
lookupY[y]= Math.sin(dx * y) * depthX;
}
var c;
for (x=0; x<w; x++){
for (y=0; y<h; y++){
c = getBilerpixel(clone, lookupY[y]+x, lookupX[x]+y);
image.SetPixel(x, y, 0, 0, c);
}
}
Find out how Vista icons differ from XP icons.
See how RealWorld Icon Editor handles Vista icons.