Line Smear - RealWorld forums

Log-in or register.

Line Smear

PAEz
on November 8th 2013

Smears lines.

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("angle", "Angle", "", 1, 360, 1);
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(distance, density, angle, mix) {
	var output = Document.RasterImage;
	var width = output.sizeX;
	var height = output.sizeY;

	var input = Document.Duplicate();
	input = input.RasterImage;
                  angle = angle/180*Math.PI;
                  var sinAngle = Math.sin(angle);
                  var cosAngle = Math.cos(angle);
                  var numShapes = parseInt(2*density*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 length = (Math.random()*Math.pow(2,32) & 0x7fffffff) % distance + 1;
                          var rgb2 = input.GetPixel(sx,sy,0,0);
                          var dx = parseInt(length*cosAngle);
                        var dy = parseInt(length*sinAngle);

                        var x0 = sx-dx;
                        var y0 = sy-dy;
                        var x1 = sx+dx;
                        var y1 = sy+dy;
                        var x, y, d, incrE, incrNE, ddx, ddy;

                        if (x1 < x0){
                                ddx = -1;
                        } else {
                                ddx = 1;
                        }
                        if (y1 < y0){
                                ddy = -1;
                        } else {
                                ddy = 1;
                        }
                        dx = x1-x0;
                        dy = y1-y0;
                        dx = Math.abs(dx);
                        dy = Math.abs(dy);
                        x = x0;
                        y = y0;

                        if (x < width && x >= 0 && y < height && y >= 0) {
                                var rgb1 = output.GetPixel(x,y,0,0);
                                var mixedRGB = mixColors(mix,rgb1,rgb2)
                   output.SetPixel(x,y,0,0,mixedRGB);
                        }
                        if (Math.abs(dx) > Math.abs(dy)) {
                                d = 2*dy-dx;
                                incrE = 2*dy;
                                incrNE = 2*(dy-dx);

                                while (x != x1) {
                                        if (d <= 0)
                                                d += incrE;
                                        else {
                                                d += incrNE;
                                                y += ddy;
                                        }
                                        x += ddx;
                                        if (x < width && x >= 0 && y < height && y >= 0) {
                                                var rgb1 = output.GetPixel(x,y,0,0);
                                                var mixedRGB = mixColors(mix,rgb1,rgb2);
                                    output.SetPixel(x,y,0,0,mixedRGB);
                                        }
                                }
                        } else {
                                d = 2*dx-dy;
                                incrE = 2*dx;
                                incrNE = 2*(dx-dy);

                                while (y != y1) {
                                        if (d <= 0)
                                                d += incrE;
                                        else {
                                                d += incrNE;
                                                x += ddx;
                                        }
                                        y += ddy;
                                        if (x < width && x >= 0 && y < height && y >= 0) {
                                                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 angle = Configuration.angle-1; // When I tried it angle was odd.  89, was 90, well straight...360 made it bug
var mix = Configuration.mix/100;
filter(size, density, angle, mix);
Page views: 1384       Posts: 1      
Select background
What about ICL files?
I wish there were...