Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions randomize expression within composition that repeats many times

  • randomize expression within composition that repeats many times

    Posted by Derek Bass on September 19, 2013 at 10:03 pm

    Hi –

    I have a composition that contains a simple opacity wiggle expression in one of its shape layers. This comp is duplicated 30 times simultaneously in another comp. I need each copy of this comp to have a different wiggle output, so that all 30 comps have a different opacity level when viewed in the parent comp.

    The expression below applies to a shape layer that is overlaid on another shape layer for a specific amount of time, so I don’t think I can apply any kind of time randomize function to each of the 30 comps in the parent comp.

    It seems like there would be a simple way to “wiggle my wiggle” so the repeated comps all have different output. Any ideas?

    op = value;
    if(op > 0 && op < 100){
    reverseAmt=100-transform.opacity;
    wiggledAmt=wiggle(flickerFrequency,reverseAmt);
    roundedAmt=Math.round((wiggledAmt/100));
    roundedAmt*100;

    Matthias Stoll replied 4 years, 8 months ago 4 Members · 10 Replies
  • 10 Replies
  • Michał Orzełek

    September 20, 2013 at 12:00 pm

    I think you should use seedRandom() function with layer index as a parameter. That will make “wiggle my wiggle” effect you described.

    Code should be sth like that (I’m not sure). Just copy and position layers.

    wiggleFreq = 2 // your frequency
    wiggleMax = 100 // max opacity
    wiggleMin = 0 // min opacity
    seedRandom(index,true); // random number per layer index
    wiggleAmout = random(wiggleMin,wiggleMax) // generates random opacity level
    wiggle(wiggleFreq,wiggleAmout) // wiggles your opacity

  • Derek Bass

    September 20, 2013 at 6:30 pm

    Thanks for the reply Michael. With your expression, I still see 30 copies of the comp on the screen all doing the same thing at the same time.

    There are other ways to do this besides using an expression, but I was hoping to go for a simple comp that I can duplicate. To keep my story simple, I didn’t mention every detail in the first post. To better explain, the comp has 3 layers:

    1. Red shape with flicker expression
    2. Light blue shape with flicker expression
    3. Dark blue shape as the base – no flicker expression

    The dark blue needs to show the most frequently, light blue, next, and red least frequently. The length of time that each shape shows is variable and random.

    This comp is repeated 30 times to form an array in the parent comp. The colors only flicker for a specific duration. The rest of the time they are dark blue.

    I feel like I’m making this a lot more complicated than it needs to be. Here’s an image of the output I’m looking for.

  • Dan Ebberts

    September 20, 2013 at 11:19 pm

    What you’re trying to do won’t work if you’ve duplicated your precomp layer 30 times. You would have to duplicate the comp in the project window so that each layer links to a different comp. Then inside each comp you could make the wiggle different by using a random seed derived from, for example, a number at the end of the comp’s name (Comp 1, Comp 2, etc.):

    n = thisComp.name.split(” “);
    seedRandom(parseInt(n[n.length-1],10));
    wiggle(1,300);

    The wiggle for that layer should be different in each comp.

    Dan

  • Derek Bass

    September 20, 2013 at 11:32 pm

    Thanks Dan. It sounds like I’d have to make 30 different compositions, which doesn’t work for my goal of keeping it simple. I was hoping there was a way to do this because there are other situations I would be able to apply similar effects to.

    To accomplish this task, I think I will end up using one or more mosaics of changing colors and overlay the negative space with a shape layer to create the right shapes.

  • Dan Ebberts

    September 20, 2013 at 11:37 pm

    It wouldn’t be too bad–you’d just have to make one comp, duplicate it 29 times, and pull them all in as layers in your main comp.

    Dan

  • Derek Bass

    September 20, 2013 at 11:48 pm

    I see what you mean now. I’m having trouble applying this to my original expression. The original expression has the variable “flickerFrequency.” How do apply this random seed based on the comp name to this?

    flickerFrequency =4;

    op = value;
    if(op > 0 && op < 100){
    reverseAmt=100-transform.opacity;
    wiggledAmt=wiggle(flickerFrequency,reverseAmt);
    roundedAmt=Math.round((wiggledAmt/100));
    roundedAmt*100;
    }

  • Dan Ebberts

    September 20, 2013 at 11:55 pm

    Like this, I would think:


    flickerFrequency =4;

    op = value;
    if(op > 0 && op < 100){
    n = thisComp.name.split(" ");
    seedRandom(parseInt(n[n.length-1],10));
    reverseAmt=100-transform.opacity;
    wiggledAmt=wiggle(flickerFrequency,reverseAmt);
    roundedAmt=Math.round((wiggledAmt/100));
    roundedAmt*100;
    }

    Dan

  • Derek Bass

    September 21, 2013 at 12:00 am

    It works! Thanks so much!

  • Michał Orzełek

    September 21, 2013 at 11:18 am

    [derek bass] “There are other ways to do this besides using an expression, but I was hoping to go for a simple comp that I can duplicate”

    Yeah. The same I was trying to do with my “randomness” problem, but unfortunately I didn’t solve it out. Maybe your code can be adjusted to my situation somehow.

  • Matthias Stoll

    January 24, 2020 at 9:15 am

    hi Dan,

    I need to read out the Name of the contents of a shape layer “Shape 1”, “Shape 2” etc. to create a delay. I want to duplicate those Shapes to get an increasing number and increasing delays.

    Something like “thisContent.name” would help – which doesn’t exist.

    Do you know about any other way to create fixed increasing numbers? I mean besides Comp names or layer indexes. I want to create a toolbox with many different shape layer animations, each reduced to one single shape layer.

    Thanks a lot!

    on transform: Shape 1

    var mult=parseInt(content(1).name.split(" ")[1]);
    var delay= effect("delay")(1)*mult;
    anim=linear(time,0+delay,2+delay,0,1);
    P.pointOnPath(anim,time)

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