I'm super close to having this right but I get very inconsistent anchor points to show up.
The problem is that sometimes I get two per pixel and sometimes it will miss some of the colors that match the hexvalue I am looking for.
I'd like for this to be consistent in adding an anchor point to the top left hand corner of the pixel that mathes the hexvalue.
Any help would be much appreciated! Code below ...
CODE: SELECT ALL
function main(){
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var myHeight = app.activeDocument.height;
var myWidth = app.activeDocument.width;
// Find pixel Color
for(var x=0; x<myWidth; x++) {
for(var y=0; y<myHeight; y++) {
activeDocument.colorSamplers.removeAll();
var sampler = activeDocument.colorSamplers.add([new UnitValue (x, 'px'), new UnitValue (y, 'px')]);
if (sampler.color.rgb.hexValue === "502905") {
var pname = 'Path ' + Math.floor(Math.random()*10000000000000000);
var startPoint = new PathPointInfo();
startPoint.anchor = [x,y];
startPoint.leftDirection = [x,y];
startPoint.rightDirection = [x,y];
startPoint.kind = PointKind.CORNERPOINT;
var stopPoint = new PathPointInfo();
stopPoint.anchor = [x,y];
stopPoint.leftDirection = [x,y];
stopPoint.rightDirection = [x,y];
stopPoint.kind = PointKind.CORNERPOINT;
var spi = new SubPathInfo();
spi.closed = false;
spi.operation = ShapeOperation.SHAPEADD;
spi.entireSubPath = [startPoint];
var line = activeDocument.pathItems.add(pname, [spi]);
}
}
}
}
main();