FORUMS: list search recent posts

# Choose a Random Null Expression

FAQ   •   VIEW ALL
 Choose a Random Null Expression on Jan 16, 2014 at 3:58:13 pm

Hi,

I am trying to make my life less tedious and i am hoping you guys out there can help!

I am creating multiple solids, each with the beam effect on them.

In the comp i have lots of randomly placed nulls and i am pic whipping the start point of the beam and the end point of the beam and putting them on random nulls.

The problem is that i am doing this manually and it is time consuming as i need thousands of lines. Does anyone know of an expression that would make the start and end of the beam choose random nulls between x-y?

 Re: Choose a Random Null Expressionon Jan 16, 2014 at 4:43:02 pm

This might help:

http://www.videocopilot.net/forum/viewtopic.php?f=5&t=59219

"|_ (°_0) _|"

Sincerely,

George

 Re: Choose a Random Null Expressionon Jan 16, 2014 at 4:52:28 pm

Awesome thanks!

One other quick thing, is it possible to put a null in a random position in a comp but only within a certain colour area?

for instance, i have a map which is black and white and i want the nulls to be in a random position but only on the land area in black, is this possible?

 Re: Choose a Random Null Expressionon Jan 16, 2014 at 5:18:45 pm

You miiiight be able to do something with sample image, but honestly, that would be above my skill level. Someone else will have to chime in for a better approach.

Could you just create an additional layer and use the black as a track matte? It wouldn't place the nulls there specifically, but it would only show anything within the black part of the image.

"|_ (°_0) _|"

Sincerely,

George

 Re: Choose a Random Null Expressionon Jan 17, 2014 at 12:07:02 am

You'd have to keep trying random positions in a loop until one gets a hit with sampleImage(). Something like this:

```l = thisComp.layer("Control Layer"); p = l.anchorPoint; min = [0,0]; max = [l.width, l.height]; black = false; maxIterations = 1000; for(x = 0; (!black && x < maxIterations); x++){ seedRandom(x, true); p = random(min, max); if(l.sampleImage(p)[0] < 0.01) black = true; } l.toComp(p);```

This would look at random points on the target "Control Layer" and whenever the red component is (almost) black would return that point translated into composition space. The last line as well as some of the details in the expression might need to be changed depending on your setup.

The "maxIterations" property is there to prevent an infinite loop in case there are no black values in the red channel on the entire layer. If the black areas are very small you may need to increase that value (and wait longer for the expression to evaluate).

Darby Edelen