where a certain color area has to be filled with random pixels within certain color shades range
How many pixels are in your selection? If you are doing it manually it can’t be that many right?
There is the selection.translateBoundary (x, y) that could move a 1x1 pixel selection. On my not too fast machine it takes about 10 sec to move and fill a selection 100 times.
#target photoshop
var docRef = app.activeDocument;
var bnds = docRef.selection.bounds
var sw = bnds[2]-bnds[0];
var sh = bnds[3]-bnds[1];
//selects the upper-left pixel of the selection
docRef.selection.select([[bnds[0], bnds[1]], [bnds[0]+1, bnds[1]], [bnds[0]+1, bnds[1]+1], [bnds[0], bnds[1]+1]] , SelectionType.REPLACE, 0, false);
var xc = 0;
var yc = 0
for (var i = 0; i < sw*sh; i++){
if(xc<sw){
docRef.selection.select([[bnds[0], bnds[1]], [bnds[0]+1, bnds[1]], [bnds[0]+1, bnds[1]+1], [bnds[0], bnds[1]+1]] , SelectionType.REPLACE, 0, false);
docRef.selection.translateBoundary (xc, yc);
}else{
xc = 0;
yc++;
docRef.selection.select([[bnds[0], bnds[1]], [bnds[0]+1, bnds[1]], [bnds[0]+1, bnds[1]+1], [bnds[0], bnds[1]+1]] , SelectionType.REPLACE, 0, false);
docRef.selection.translateBoundary (xc, yc)
}
docRef.selection.fill(randomHSB(200, 220));
xc++
};
/**
* returns a random HSB color
* @returns a SolidColor
*
*/
function randomHSB(hmin, hmax){
colorobj = new SolidColor()
colorobj.hsb.hue = getRndInteger(hmin, hmax);
colorobj.hsb.saturation = getRndInteger(10, 100);
colorobj.hsb.brightness = getRndInteger(30, 100);
return colorobj;
};
/**
* @ returns a random number between min and max
*
*/
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
};
