by Gary Noden on Jul 4, 2014 at 1:57:43 pm
I am trying to work out if it's possible to create a script that applies a series of effects to a layer based on a colour analysis of a pixel, e.g., if the pixel at this coordinate is red, apply these effects, if the colour is green apply these effects, and so on so I can put a splat of a colour in the corner of a SWF in flash and from it apply the correct effects for that animation layer.
Is there a way of calling this information in a script, such as using the colour picker to evaluate what they are? I can do something similar to this in Maya, but my knowledge of Adobe's extendscript is limited at present.
Re: Colour analysis by Kevin Camp on Jul 4, 2014 at 4:45:15 pm
you may be able to do this with expressions.
expressions can't add effects, but they can modify properties. so you may be able to have various properties look at a color and set themselves accordingly.
i'm not sure this will work for your situation, but say you can add the effects to an adjustment layer. you can have the opacity of the adjustment layer look at the color of a pixel on a layer and set it to 100 if the pixel is red and 0 if it is not, effectively turning the effects on or off based on the pixel's color.
to sample a pixel using expressions you'd use the sampleImage() function. a basic expression to get the color value of a pixel would be like this:
sourceLayer = thisComp.layer("My Source Layer"); // layer you want to sample
p = [0,0]; // position of the pixel you want to sample
r = [.5,.5]; // radius of the sample point
the expression will return a RGBA array in decimal form, so red would be [1,0,0,1].
an advantage of expressions would be you don't need to run it after a change, it will update as a change occurs. a disadvantage is that it will evaluate at every frame in the animation, so rendering will take longer - how much longer depends on how heavy the expressions are.