ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

play keyframes at random time

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Marc Rühl
play keyframes at random time
on Mar 17, 2017 at 5:20:48 pm

I have a layer with some scale keyframes. Now I would like to loop this animation BUT with a random pause between the loops.
Since it would great if the loop also switches it's position with every loop I thought it would be a good idea to have an independant value, which could be read from the position and the scale expression.
Maybe something like a slider which randomly switches from 0 to 1, to make the position change and start the loop again.
This would then be the expression for this slider

But I'm still not sure if this is really the way to go, since I'm having a hard time figuring out the expression for position and the scale keyframes.

segMin = .5; //minimum segment duration
segMax = 2.5; //maximum segment duration
Dur = .05;

end = 0;
j = 0;
while ( time >= end){
j += 1;
seedRandom(j,true);
start = end;
end += random(segMin,segMax);
}
if (time > end - Dur){
1;
}else{
0
}


http://www.schwarzgrau.com


Return to posts index

Marc Rühl
Re: play keyframes at random time
on Mar 20, 2017 at 12:24:33 pm

I used one of Dan Ebberts Random Motion scripts to figure out the first part of this expression construction. I thought I should share it, since maybe someone else could find it helpful.
This expression will loop the existing keyframes of this property in a random timespan of 1 to 5 seconds.

PSEmin = 1;
PSEmax = 5;

end = 0;
j = 0;
while ( time >= end){
j += 1;
seedRandom(j,true);
start = end;
end += random(PSEmin,PSEmax);
}

MT = time - start;

valueAtTime(MT);


http://www.schwarzgrau.com


Return to posts index

Marc Rühl
Re: play keyframes at random time
on Mar 20, 2017 at 12:56:38 pm

So it seems I got everything working. I honestly have no idea if someone will find it useful, but I'll post it anyways.

This example layer has a few keyframes on scale and a point control effect applied, which is called timer.
EXPRESSION 1 does all the magic and is applied on the point control effect. (It's only a point control to get access to two values)
EXPRESSION 2 is applied on scale and
EXPRESSION 3 is applied on position and will make the layer jump to a new position every time the keyframes get "played"

------------------------------------------------------
EXPRESSION 1

PSEmin = 1;
PSEmax = 5;

end = 0;
j = 0;
while ( time >= end){
j += 1;
seedRandom(j,true);
start = end;
end += random(PSEmin,PSEmax);
}
[start,end]

------------------------------------------------------
EXPRESSION 2

start = effect("timer")("Point")[0]
MT = time - start;

valueAtTime(MT);

------------------------------------------------------
EXPRESSION 3

maxX = 600;
maxY = 600;
start = effect("timer")("Point")[0]
seedRandom(start,true);
Xpos = random(maxX);
Ypos = random(maxY);
[Xpos,Ypos]


http://www.schwarzgrau.com


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]