Circle Smear - RealWorld forums

Log-in or register.

Circle Smear

PAEz
on November 8th 2013

Um....smears circles on your image.
Be warned the Size parameter affects the time it will take alot.

Code
Configuration

Configuration.AddSlider("size", "Size", "Be warned, the larger the size the longer it will take, keeping it under 10 is sane.", 1, 100, 4);
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;
                //parseInt(size); // the size got turned to an int....wonder why?...it seemed to work when it didnt
                  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++){
                                        var f = (x - sx) * (x - sx) + (y - sy) * (y - sy);
                                        if (x >= 0 && x < width && y >= 0 && y < height && f <= radius2) {
                                                var rgb1 = input.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);

Note to self...
Replace the Math.random function with something that is seedable so that the preview will match the result and so the settings are portable.

Page views: 2280       Posts: 1      
What about ICL files?
Select background
I wish there were...