Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions random dots fade in at spec time

  • random dots fade in at spec time

    Posted by Nate Hurwitz on February 26, 2010 at 3:04 am

    Hi Guys,

    Looking to wrap my head around trying to write out an expression for multiple layers.

    The Scenario: I have multiple dots I would like to fade in one at a time over a controlled period of time. Each dot is a separate shape layer. The fade time between dots would also be controllable (although I think I might be repeating myself by already stating I’d like to control this over a period of time).

    This script would be applied to 40 layers. Any help or information on where to start would be greatly appreciated! Thanks!

    Tim Bright replied 12 years, 10 months ago 4 Members · 12 Replies
  • 12 Replies
  • Dan Ebberts

    February 26, 2010 at 8:57 pm

    So does each dot fade in at a random time sometime during the specified interval, or do the dots fade in sequentially in random order? In the first scenario, the timing is random. In the second scenario, the timing is fixed, but the order of the dots is random.

    Dan

  • Nate Hurwitz

    February 27, 2010 at 7:43 pm

    Hi Dan,

    Thanks for the response!

    I’m looking to fade the dots with fixed timing in random order (so they all fade in by a certain time randomly).

    To give you a picture, the dots represent different locations fading in on a map territory while a camera is panning over the particular territory. I began doing this by hand, but figured with expressions that there had to be a better way. I am still very new to expressions and am looking forward to any advice, thanks!

    Nate Hurwitz
    Digital Media Arts/Music Major
    Do you love it?

  • Dan Ebberts

    February 27, 2010 at 9:52 pm

    This example should help. This assumes all layers in the comp are participating If that’s not the case then you’ll need to adjust the way “n” is calculated.

    Add a slider to the top layer in the layer stack and give it this expresssion:

    theArray = [];
    seedRandom(index,true);
    n = thisComp.numLayers;
    for (i = 0; i < n; i++) theArray[i] = i+1; for (i = 0; i < n; i++){ idx = i + Math.floor(random(theArray.length - i)); temp = theArray[i]; theArray[i] = theArray[idx]; theArray[idx] = temp; } i = Math.floor(time); if (i >= 0 && i < n) theArray[i] else 0 This expression tells each of the layers when it's their turn to fade in. Now add this Opacity expression to each of the layers (including the one with the slider): timeStart = 2; timeEnd = 5; s =thisComp.layer(1).effect("Slider Control")("Slider"); mySeg = s.valueAtTime(index-.5)-1; dur = timeEnd - timeStart; n = thisComp.numLayers; segDur = dur/n; myStart = timeStart + mySeg*segDur; myEnd = myStart + segDur; linear(time,myStart,myEnd,0,100) The variables timeStart and timeEnd set the time span for all the layers to fade in. The time will be divided equally amongst the layers and they will fade in in random order. Dan

  • Nate Hurwitz

    February 28, 2010 at 5:53 am

    Hi Dan,

    Thanks a lot, I will try this and let you know how it works out. I really appreciate the time you take out of your day to help those with questions out. Thanks!

    Nate Hurwitz
    Digital Media Arts/Music Major
    Do you love it?

  • Steven Tiell

    March 26, 2013 at 5:06 pm

    This is EXACTLY what I want to do, except I’m doing it with a word cloud of ~100 words. I am a total novice to AE, but happen to have CS6 on my computer and would love to figure this out. I can’t seem to figure out how to (1) add a slider, or (2) add an opacity expression.

    I found this tutorial – https://provideocoalition.com/ryoung/story/using_and_creating_after_effects_scripts/ – about using scripts in AE CS6 and followed its instructions, but nowhere do I see the slider reference. Furthermore, these scripts don’t seem to have the “fuction ()” format of other JavaScript functions, so I’m even further confused. Can you add any further insight? Thanks!

  • Dan Ebberts

    March 26, 2013 at 6:34 pm

    I’m confused about what you’re trying to do exactly. If you’re just talking about adding a slider and an expression, sliders are actually an effect that you can add to a layer from the Effect menu or the Effects & Presets panel. You add an expression by Alt/Opt clicking the property’s stopwatch and pasting in your expression code.

    If you are instead talking about having a script perform these actions for you, that’s a completely different converstation.

    Dan

  • Steven Tiell

    March 26, 2013 at 7:25 pm

    Okay. Great. I figured out how to add the slider…and the code…and I’m still getting an error. Let me back up. Here’s my word cloud:

    I imported the file from Illustrator and did “Create Shapes from Vector Layer” and got 94 “Groups” under “Content” within my timeline item.
    I added the slider & your first snippet of code to the slider:

    And then I added your 2nd snippet of code to “Group 94”:

    And then I get this error:

    I’m confused. Clearly, the effect named “Slider Control” exists. I even tried to put the “Slider Control” effect on the null layer, but got the same error.

    My end goal is to get each of the words in the word cloud to randomly appear (fade in). Then I want to export an animated GIF for a PPT deck (sadly enough).

    effect("Slider Control")(1)
    theArray = [];
    seedRandom(index,true);
    n = thisComp.numLayers;
    for (i = 0; i &lt; n; i++) theArray[i] = i+1;
    for (i = 0; i &lt; n; i++){
    idx = i + Math.floor(random(theArray.length - i));
    temp = theArray[i];
    theArray[i] = theArray[idx];
    theArray[idx] = temp;
    }
    i = Math.floor(time);
    if (i >= 0 && i &lt; n) theArray[i] else 0

    content("Group 94").transform.opacity
    timeStart = 2;
    timeEnd = 5;
    s =thisComp.layer(1).effect("Slider Control")("Slider");
    mySeg = s.valueAtTime(index-.5)-1;
    dur = timeEnd - timeStart;
    n = thisComp.numLayers;
    segDur = dur/n;
    myStart = timeStart + mySeg*segDur;
    myEnd = myStart + segDur;
    linear(time,myStart,myEnd,0,100)

  • Dan Ebberts

    March 26, 2013 at 8:07 pm

    Ah, OK–I see the problem. The expressions assume that each entity is a separate layer, but in your case it’s all contained in one layer. So you wouldn’t need a null, you would just add the slider to your word layer and add this expression to it:

    n = content.numProperties;
    theArray = [];
    seedRandom(index,true);
    for (i = 0; i < n; i++) theArray[i] = i+1;
    for (i = 0; i < n; i++){
    idx = i + Math.floor(random(theArray.length – i));
    temp = theArray[i];
    theArray[i] = theArray[idx];
    theArray[idx] = temp;
    }
    i = Math.floor(time);
    if (i >= 0 && i < n) theArray[i] else 0

    Now the bad news. You will need to add the following expression to each of the 94 group’s Opacity property:

    n = content.numProperties;
    timeStart = 2;
    timeEnd = 5;
    s = effect(“Slider Control”)(“Slider”);
    myName = thisProperty.propertyGroup(2).name;
    myNum = parseInt(myName.split(” “)[1]);
    mySeg = s.valueAtTime(myNum-.5)-1;
    dur = timeEnd – timeStart;
    segDur = dur/n;
    myStart = timeStart + mySeg*segDur;
    myEnd = myStart + segDur;
    linear(time,myStart,myEnd,0,100)

    That’s where a script might come in handy to automate the process of adding the expressions. But if this is a one-off, it would probably be faster to just do it by hand (especially if you’re unfamiliar with scripting in After Effects).

    Dan

  • Steven Tiell

    March 26, 2013 at 8:44 pm

    This is awesome and it’s working! I’ve got it about half finished now. just one question before I do the next half…If I want to adjust the overall time that it takes, I have to make that modification in the code of every single group element, right? So say I want it to last 2 seconds, I’d do

    timeStart = 0;
    timeStop = 2;

    Is there a way to over-ride the group values from the slider expression so I only have to make that adjustment in one place?

  • Dan Ebberts

    March 26, 2013 at 8:55 pm

    You could tie those values to sliders. Just add two more sliders to the layer, rename them “Start Time” and “End Time”, set their values to whatever you want, and then replace the two lines in the Opacity expression with:

    timeStart = effect(“Start Time”)(“Slider”);
    timeEnd = effect(“End Time”)(“Slider”);

    Dan

Page 1 of 2

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