Square Smear - RealWorld forums

Log-in or register.

Square Smear

PAEz
on November 8th 2013

Code
Configuration

Configuration.AddSlider("size", "Distance", "Be warned, the larger the size the longer it will take.", 1, 100, 8);
Configuration.AddSlider("density", "Density Percentage", "", 1, 100, 50);
Configuration.AddSlider("mix", "Mix Percentage", "Who much of the smear to mix with orginal image, 1 will replace the image.", 1, 100, 50);

Execution

// Joel Besada
// https://github.com/JoelBesada/JSManipulate
// Plus PAEz touch here and there

this.mixColors = function(t, rgb1, rgb2){
          var r = this.linearInterpolate(t,rgb1 >> 16 & 255,rgb2 >> 16 & 255);
          var g = this.linearInterpolate(t,rgb1 >> 8 & 255,rgb2 >> 8 & 255);
          var b = this.linearInterpolate(t,rgb1 & 255,rgb2 & 255);
          var a = this.linearInterpolate(t,rgb1 >> 24 & 255,rgb2 >> 24 & 255);
          return b | (g << 8) | (r << 16) | (a << 24);
  }

  this.linearInterpolate = function(t,a,b){
          return a + t * (b-a);
  }

filter = function(size, density, mix) {
	var output = Document.RasterImage;
	var width = output.sizeX;
	var height = output.sizeY;

	var input = Document.Duplicate();
	input = input.RasterImage;
                  var radius = size+1;
                  var radius2 = radius*radius;
                  var numShapes = parseInt(2*density/30*width*height / 2);
                  for(var i = 0; i < numShapes; i++){
                          var sx = (Math.random()*Math.pow(2,32) & 0x7fffffff) % width;
                          var sy = (Math.random()*Math.pow(2,32) & 0x7fffffff) % height;
                          var rgb2 = input.GetPixel(sx,sy,0,0);;
                        for(var x = sx - radius; x < sx + radius + 1; x++){

                                for(var y = sy - radius; y < sy + radius + 1; y++){
                                        if (x >= 0 && x < width && y >= 0 && y < height) {
                                                var rgb1 = output.GetPixel(x,y,0,0);;
                                                var mixedRGB = mixColors(mix,rgb1,rgb2)
                                    output.SetPixel(x,y,0,0,mixedRGB);
                            }
                                }
                        }
                  }
}

var size = Configuration.size;
var density = Configuration.density/100;
var mix = Configuration.mix/100;
filter(size, density, mix);
Page views: 3011       Posts: 1      
Vista & Win 7 icons
What about ICL files?
Select background