Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Eye-Blink Expression

  • Lewis Snook

    December 22, 2016 at 8:37 am

    Yeah, I’ve been using this expression for a while. It’s great until you have a longer comp, then it can really slow down the render times and for some reason the expression takes longer to calculate the longer it is used.
    So for my purposes, is there a way to make this random effect without the looping calculation (I don;t quite understand the above answer), or would I have to use an expression that has this effect (I don;t quite understand the above answer):

    every 3 seconds it decides whether to blink or not.
    still keeping in the fadeTime and blinkDur

    And will this get rid of the loop factor that the ‘while” expression brings?

    Thanks

  • Dan Ebberts

    December 22, 2016 at 5:04 pm

    Something like this maybe:


    segDur = 3; // blink once in every 3-second period
    blinkDur = .25;
    fadeTime = .1;
    seg = Math.floor(time/segDur);
    seedRandom(seg,true);
    tStart = random(segDur-blinkDur);
    t = time - seg*segDur;
    if (t < tStart + blinkDur/2)
    easeOut(t,tStart,tStart+fadeTime,0,100)
    else
    easeIn(t,tStart+blinkDur-fadeTime,tStart+blinkDur,100,0);

    Dan

  • RP Koop

    May 26, 2023 at 10:12 pm

    Hi Dan

    This is a great script.

    Question is, can I attach a sound to each ‘flash’ generated. Do you think its possible using your script? I have the sounds all ready to go in AE; just daunted by locating and inserting them in the timeline to coincide with the script. The timing of each flash is simple, meaning they occur regularly: i.e. minSeg and maxSeg are the same. So what do you think?

  • Dan Ebberts

    May 27, 2023 at 12:40 am

    Which version of the expression are you using? If you have it set up to run periodically rather than randomly, there’s probably a simpler solution.

  • RP Koop

    May 28, 2023 at 8:34 pm

    The script is perfect. I have over a thousand events, each requires precise inputs (from data) but I can make the segStart and segEnd the same for each single data entry / event (but obviously not for the entire set of data together). So every one of the 1000+ entries is unique. However for every one, individually, the segStart and segEnd can be the same (or for some variation, as I have it now, there’s a 0.1 difference. This is the version I’m using (below). Thanks.

    ps. so the combination for each data point is different i.e. minSeg, maxSeg blinkDur and fadeTime are always different from the previous data point. BUT within each dat point I can have the same minStart and maxEnd.

    minSeg = 2.0;
    maxSeg = 5.0;
    blinkDur = .25;
    fadeTime = .1;

    seedRandom(index,true)
    segStartTime = -random(minSeg,maxSeg);
    segEndTime = segStartTime;
    i = 1;

    while (time >= segEndTime){
    i += 1;
    seedRandom(i,true);
    segStartTime = segEndTime;
    segEndTime = segEndTime + random(minSeg,maxSeg);
    }

    if (time < segStartTime + blinkDur/2)
    easeOut(time,segStartTime,segStartTime+fadeTime,0,100)
    else
    easeIn(time,segStartTime+blinkDur-fadeTime,segStartTime+blinkDur,100,0)

  • Dan Ebberts

    May 28, 2023 at 9:23 pm

    Hmmm. Ok. Since there’s a random component, it sounds like you need the randomizing part in a separate expression with the result “published” for both the flash and sound expressions to use. I’m still not clear on how you have this set up, so I’m going to describe how I’d do this for one flash layer and one sound layer. I’d create a null layer named “Control”, add a slider to it, and add this expression to the slider:

    minSeg = 2.0;
    maxSeg = 5.0;
    seedRandom(index,true)
    segStartTime = -random(minSeg,maxSeg);
    segEndTime = segStartTime;
    i = 1;
    while (time >= segEndTime){
    i += 1;
    seedRandom(i,true);
    segStartTime = segEndTime;
    segEndTime = segEndTime + random(minSeg,maxSeg);
    }
    segStartTime

    This calculates and publishes the randomized segStartTime. Then your flash expression becomes:

    blinkDur = .25;
    fadeTime = .1;
    segStartTime = thisComp.layer("Control").effect("Slider Control")("Slider");
    if (time < segStartTime + blinkDur/2)
    easeOut(time,segStartTime,segStartTime+fadeTime,0,100)
    else
    easeIn(time,segStartTime+blinkDur-fadeTime,segStartTime+blinkDur,100,0)

    You would turn on time remapping for your sound, drag the right edge so the layer duration matches the comp, and add this time remapping expression:

    segStartTime = thisComp.layer("Control").effect("Slider Control")("Slider");
    Math.max(time - segStartTime, 0)

    That should sync the sound to the flash.

    Now you mention 1000+ entries and I’m not sure if that implies 1000+ control layers and 1000+ sound layers or not. If so, then maybe this isn’t of much help to you. I’m hoping you can adapt this to your situation somehow though.

  • RP Koop

    May 29, 2023 at 7:42 am

    Thanks Dan. Yes, there are over 1000 calculations going on for each separate layer so I’m assuming each is going to need their own control layer and sound layer. Could become a mess! The layers are simple blocks of colour, but each block has to be on a separate layer for the data to act properly.

  • RP Koop

    June 2, 2023 at 6:26 pm

    Hi, getting this: Error at line 1 in property ‘Position of Layer 5 (‘Control’) in comp… Expression Error: Expression result must be of dimension 2, not 1. It underlines the first line of your code: minSeg =


    Thanks

  • Dan Ebberts

    June 2, 2023 at 6:32 pm

    The minSeg expression is supposed to be applied to a slider. What property did you apply it to?

  • RP Koop

    June 2, 2023 at 7:17 pm

    brilliant, sorry, had it on the wrong layer.

    I think I’m going to just do this to the 1000 layers. I suppose I need to call each control layer by a unique name, right; so that each finds their own slider?

Page 3 of 4

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