Activity › Forums › Adobe After Effects Expressions › Expression for “controlled” random opacity
-
Expression for “controlled” random opacity
Posted by Joakim Dalfors on July 19, 2006 at 10:48 amAny expression experts out there?
IJoakim Dalfors replied 19 years, 9 months ago 4 Members · 7 Replies -
7 Replies
-
Joel Hooton
July 19, 2006 at 2:24 pmYou can use layer markers (press the * on the number pad when the layer is selected) to activate expressions.
if (marker.num_keys > 0){
m = marker.nearest_key(time).index;
x=m%2;
if ( marker.key(m).time <= time && x==1){ Y }else if (marker.key(m).time>time && x==0){
Y
}else{
X
}
}else{
0
}Basically this expression can be applied to the opacity of the layer. The value changes from X (before the first marker) to Y (between the next two) and then back to X between the next two. This continues for as long as you have layer markers. Just change the value of Y to a random funtion and then between the layer markers you will have random motion.
I also have setup may other expressions to vary value for layer markers. Here is my tutorial on the cow
https://forums.creativecow.net/cgi-bin/page_wrapper.cgi?forumid=2&page=https://www.creativecow.net/articles/hooton_joel/synch_video_to_audio/index.html
JoelP4 2.6 Ghz/512 MB RAM/AE 6.5 Pro
-
Joakim Dalfors
July 19, 2006 at 2:57 pmHi Joel!
Thanks for your input and I definately will check out the tutorial since driving expressions with markers seems like a useful idea.
In this particular case it might be a step forward but I would still need to put out a lot of markers. I -
Mylenium
July 19, 2006 at 3:21 pmYou should create a “master” layer that goes thru the animation cycle at least once (can be totally manually keyframed) and then use valueAtTime()to remap this animation to other layers. You could e.g. use random() to define different cycle. Something like this may be a place to start:
seedRandom(index,true);
master=thisComp.layer(“Master”).opacity;
master_start=0; //start time of reference cycle
master_end=3; //end time of reference cyclemin_cycle=1; //minimum cycle in seconds
max_cycle=5; //maximum cycle in secondsreal_cycle=random(min_cycle,max_cyle); //random cycle length
real_time= (master_end-master_start)/real_cycle //time multiplier
new_opacity=master.valueAtTime(time%real_cycle*real_time);
[new_opacity]
Dunno off the top of my if it is correct, but it should produce something usable.
Mylenium
[Pour Myl
-
Dan Ebberts
July 19, 2006 at 3:35 pmGive this a try:
A = 3;
B = 7;
C = 5;
D = 11;f = Math.round(time/thisComp.frameDuration);
t = 0;
j = 0;
while (f >= t){
j++;
seedRandom(j,true);
period1 = Math.round(random(A,B));
period2 = Math.round(random(C,D));
t += period2 + period1 + 2
}
if (f < t - (period2 + 2)){ 0 }else if (f < t - (period2 + 1)){ random(100) }else if (f < t - 1){ 100 }else{ random(100) } Dan -
Dan Ebberts
July 19, 2006 at 4:00 pmI may have misunderstood. My previous example will vary the random values. If what you want is one set of random values that repeats forever, this should do it. You can, of course, connect A, B, C, and D to sliders if you want.
A = 3;
B = 7;
C = 5;
D = 11;f = Math.round(time/thisComp.frameDuration);
seedRandom(index,true);
period1 = Math.round(random(A,B));
period2 = Math.round(random(C,D));
t = period1 + period2 + 2
d = f%t;
if (d < period1){ 0 }else if (d < period1 + 1){ random(100) }else if (d < period1 + period2 + 1){ 100 }else{ random(100) } Dan -
Joakim Dalfors
July 19, 2006 at 4:44 pmHi Mylenium!
Thanks very much! Apart from two minor spelling errors your code worked as expected and when watching the comp in its context I may be ready to use it as it is but my curiosity is eager to know how you can randomize the cycle as you mentioned in your post.
For now, I just did a manually keyframed cycle with the average desired dutycycle (corresponding to 2 frames off, 1 frame semitransparent, 4 frames on and 1 frame semitransparent), but I guess the result would be even more pleasing if I could randomize that a bit (which is why I had four “input constants” in my original request).Thanks again
/Jocke -
Joakim Dalfors
July 19, 2006 at 5:27 pmHi Dan!
You must be the “God of expressions”!
You got it perfectly right the first time and it works just perfect.Many thanks for this (and your tutorials about expressions)
/Jocke
Reply to this Discussion! Login or Sign Up