Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Ensuring two ‘random’ expressions do not produce same value

  • Ensuring two ‘random’ expressions do not produce same value

    Posted by Marcus Round on January 14, 2015 at 11:01 am

    I have a Beam that I want to go from one randomly selected Blob to another.

    So I select a random Blob for the “Start Point” of the Beam:

    blobs = thisComp.layer("2").content("Blobs");
    numBlobs = blobs.numProperties;
    myBlob = Math.ceil(random(numBlobs));

    anchorPoint+blobs.content(myBlob).transform.position;

    So far, so good. Plug the same expression into the “End Point” of the beam, and there’s a chance that the Beam will pick the same Blob as both its start and end point, which we don’t want.

    I thought I’d be clever and put this into the “End Point”:

    blobs = thisComp.layer("2").content("Blobs");
    numBlobs = blobs.numProperties;
    myBlob = Math.ceil(random(numBlobs));

    start = thisLayer("Effects")("Beam")("Starting Point");
    do{
    end = anchorPoint+blobs.content(myBlob).transform.position;
    }while(start == end);
    end

    But this doesn’t seem to have any effect. Any ideas?

    Dan Ebberts
    replied 11 years, 3 months ago
    2 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    January 14, 2015 at 5:57 pm

    I think I would add a point control to the layer with the Beam effect so that you can do the calculation for both points all in one place, with something like this (not tested(:

    blobs = thisComp.layer(“2”).content(“Blobs”);
    numBlobs = blobs.numProperties;
    blob1 = Math.floor(random(numBlobs));
    blob2 = (blob1 + Math.floor(random(numBlobs-1)))%numBlobs;
    [blob1+1,blob2+1]

    Then your starting point and ending point expressions would look like this:

    Math.round(effect(“Point Control”)(“Point”)[0])

    and

    Math.round(effect(“Point Control”)(“Point”)[1])

    Dan

  • Marcus Round

    January 15, 2015 at 3:30 pm

    Thanks Dan,

    But I’m not sure I was clear. If I’m reading your code correctly, each expression will output a single number (either the x or y co-ordinate of a point), but I am looking to pick two different points.

    After tinkering around, from what I can find the problem with my original code is perhaps to do with the use of arrays in conditional statements.
    I tried paring it down to its simplest essence: I made a text layer, and added a point control to the text layer. In the source text, I put this code:

    if(effect("Point Control")("Point")==[600,600]){"true"}else{"false"}

    Which seems fairly straight-forward, but the point control is set to 600,600 and it still evaluates to “false”. Am I doing something wrong?

    In my original code, I am checking if “start” and “end” are equal, and both are arrays.

  • Dan Ebberts

    January 15, 2015 at 4:59 pm

    I’m sorry, I botched the expressions for the starting and ending point expressions. What you get from the expression in the point control is two blob numbers, one for start one for end. So your starting and ending point expressions should pick those up, but then use them as you used myBlob in your original expression.

    Dan

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