Scatters pixels.
Code
Configuration
Configuration.AddSlider("scale", "Scale", "", 1, 100, 4);
Execution
// Joel Besada
// https://github.com/JoelBesada/JSManipulate
// Plus PAEz touch here and there
function getBilerpixel(l, x, y, w, h) {
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;
}
transformFilter = function(inputData, outputData, transformInverse, width, height) {
var out = [];
for (var y = 0; y < height; y++) {
for (var x = 0; x < width; x++) {
transformInverse.apply(this, [x, y, out]);
var srcX = out[0];
var srcY = out[1];
var w = width - 2;
var h = height - 2;
var direction = 1;
while (srcX < 0 || srcX > w) {
if (srcX > w) {
srcX = w - (srcX - w);
direction = -1;
}
if (srcX < 0) {
srcX *= -1;
direction = 1;
}
}
while (srcY < 0 || srcY > h) {
if (srcY > h) {
srcY = h - (srcY - h);
direction = -1;
}
if (srcY < 0) {
srcY *= -1;
direction = 1;
}
}
//var srcX2=srcX+direction;
//var srcY2=srcY+direction;
var rgba = getBilerpixel(inputData, srcX, srcY, width - 1, height - 1);
outputData.SetPixel(x, y, 0, 0, rgba);
}
}
}
filter = function(scale) {
var input = Document.RasterImage;
var width = input.sizeX;
var height = input.sizeY;
var clone;
clone = Document.Duplicate();
clone = clone.RasterImage;
var sinTable = [];
var cosTable = [];
for(var i = 0; i < 256; i++){
var angle = Math.PI*2*i/256;
sinTable[i] = scale*Math.sin(angle);
cosTable[i] = scale*Math.cos(angle);
}
transInverse = function (x,y,out){
var angle = parseInt(Math.random() * 255);
var distance = Math.random();
out[0] = x + distance * sinTable[angle];
out[1] = y + distance * cosTable[angle];
}
transformFilter(clone, input, transInverse, width, height);
}
var scale = Configuration.scale;
filter(scale);