Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Choose a Random Null Expression

  • Choose a Random Null Expression

    Posted by David Bland on January 16, 2014 at 3:58 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?

    Thanks in advance!

    Darby Edelen replied 12 years, 7 months ago 3 Members · 5 Replies
  • 5 Replies
  • George Goodman

    January 16, 2014 at 4:43 pm

    This might help:

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

    “|_ (°_0) _|”

    Sincerely,

    George

  • David Bland

    January 16, 2014 at 4:52 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?

  • George Goodman

    January 16, 2014 at 5:18 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

  • Darby Edelen

    January 17, 2014 at 12:07 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

  • Darby Edelen

    January 18, 2014 at 6:08 am

    Just a quick addendum to my last post. The expression there will re-evaluate the control layer on every frame, so if the black/white sections change over time (fractal noise with evolution animated for example) the Nulls will choose a new random position whenever their position is no longer over black.

    Darby Edelen

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy