Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions blink expression

  • Posted by Nicholas Toth on May 15, 2006 at 3:36 pm

    Hey guys. Trying to make a character blink.
    Basically I’m trying to set it up so every 3 seconds we decide if it wants to blink or not. If it does, then it’ll hold the duration of the blink for 15 frames or .5 seconds.

    This is where I am:

    holdTime = 2
    seed = (time/holdTime);
    seedRandom(seed,true);
    random(0,100)

    if ( opacity => 50){
    100
    }else{
    0
    }

    if ( opacity = 100){
    holdTime = .5
    }else{
    2
    }

    I’m trying to say pick a random number between 100 and 0,then round it to 100 or 0 based on its value, and if it is 100 then change the hold time to a half second.
    I really want to set it up so it rolls the dice every two seconds, but I can’t figure it out. I have my manual open in front of me, and just can’t crack it.

    The blink is just another layer that sits on the character.

    Nicholas Toth replied 20 years ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    May 15, 2006 at 4:27 pm

    Start with this, then let’s take it from there:

    period = 2
    holdTime = 0.5;

    seed = Math.floor(time/period);
    t = time%period
    seedRandom(seed,true);
    if ( random() > .5 && t < holdTime) 100 else 0; Dan

  • Nicholas Toth

    May 15, 2006 at 5:17 pm

    Thanks Dan —

    Now one last question — what does that code mean and why didn’t mine work?
    I’ve been referencing your site and it is super helpful, i just wasn’t expecting this code to be so simple.

  • Dan Ebberts

    May 15, 2006 at 8:14 pm

    The code just calculates a new random seed every 2 seconds and uses that to generate a random number between 0 and 1, which it uses to decide whether the opacity should be off or on. If it should be on, it also makes sure that it has been on for less than .5 seconds (holdTime) or else it turns opacity off.

    Yours seems to have several problems. First, your seed calculation will produce a new seed every frame (not very useful). Then you generate a random number, but don’t assign it to a variable. Then you test the layer’s opacity (which will always be the same value unless you have keyframed it). Then you test the opacity value again (by the way the JavaScript equality test is == not =) and depending on the result you either set holdTime to .5 (and then never use that value) or set opacity to 2 (?)

    I’m guessing you’re confused by the fact that an expression can’t pass info to itself from one frame to the next. Any time you reference the value of the property that the expression is applied to you get the static (or keyframed) value, not the one generated previously by the expression.

    Dan

  • Nicholas Toth

    May 15, 2006 at 8:31 pm

    thanks — understanding it is half the battle

  • Chris Zwar

    May 16, 2006 at 1:04 pm

    There’s usually nothing to add to Dan’s posts about expressions, but in this case I was doing a similar thing last week. As Dan points out, expressions cannot maintain variables between each frame, so that means you always have to use Time as the starting point for your calculations.

    In my case, I was moving an animated character’s eyes, and I had a source composition with all the different possible eye movements in it as a sequence of stills. The expressions I wrote was applied to Time Remapping of that composition, which would call up the relevant eye image.

    If you wanted to take your project 1 step further again, then you could use the Time Remapping technique to get your character to blink with an animated sequence of frames- but you would have to set up an iterative loop, based on the Time of each frame, to calculate which frame should be shown when. It might sound messy but it’s kinda straightforward, and worked well for me.

    -Chris Zwar

  • Nicholas Toth

    May 16, 2006 at 2:22 pm

    the remapping of a blink sequence sounds like it may be my next approach — gotta step it up

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