ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Random Brightness value for a layer with FADE / OPACITY / TRANSITION (in-between).

FAQ   •   VIEW ALL
 Random Brightness value for a layer with FADE / OPACITY / TRANSITION (in-between). on Mar 12, 2018 at 10:58:59 am

I've used this code to set a random brightness value for each colored rectangle:
```effect("Brightness & Contrast")(1) minVal = 0; maxVal = 200; minDur = .6; maxDur = .6; seedRandom(index,true); tNext = tPrev = 0; while (tNext <= time){ tPrev = tNext; tNext += random(minDur,maxDur); } seedRandom(tPrev,true); random(minVal,maxVal) ```
Right now for every 6 frames it gets some values [21] >[88] > [94] > [133] > etc.
(so on frame 0 is Brightness: 21, on frame 6 is Brightnes:88, etc.)

I want to have something like this (so each number represents the value on a single frame):

[21] > 32 > 43 > 54 > 66 > 77 > [88] > 89 > 90 > 91 > 92 > 93 > [94] > ... > ... > ... > ... > ... > [133] > etc.

Is there a way to set a random value for the Brightness effect and fade / have a transition of fade/opacity from a value to another?

So it goes like a smooth/linear in-between the values instead of a step/hold transition.

Thanks!

 Re: Random Brightness value for a layer with FADE / OPACITY / TRANSITION (in-between).on Mar 12, 2018 at 1:14:48 pm

The first and easiest way that come up my mind is to put your expression intro a slider-effect and then put a smooth expression into your brightness effect like this:
`effect("slider")(1).smooth(0.6,10);`

Its difficult to smooth something in a expression I think, its easier to work with a little help-effect and then use the output of it to smooth it or even to access the expression to a different time and so on.

 Re: Random Brightness value for a layer with FADE / OPACITY / TRANSITION (in-between).on Mar 12, 2018 at 1:40:17 pm

 Re: Random Brightness value for a layer with FADE / OPACITY / TRANSITION (in-between).on Mar 12, 2018 at 4:21:34 pm

Play around with this one:

minVal = 0;
maxVal = 200;
dur = .6;
curSeg = Math.floor((time-inPoint)/dur);
t = (time-inPoint)%dur;
seedRandom(curSeg,true);
vPrev = random(minVal,maxVal);
seedRandom(curSeg+1,true);
vNext = random(minVal,maxVal);
linear(t,0,dur,vPrev,vNext)

Dan

 Re: Random Brightness value for a layer with FADE / OPACITY / TRANSITION (in-between).on Mar 13, 2018 at 3:58:43 pm

That doesn't work that well, it's better but is still flickering (not a smooth transition).

 Re: Random Brightness value for a layer with FADE / OPACITY / TRANSITION (in-between).on Mar 13, 2018 at 5:17:51 pm

There may be some kind of round off error going on. Try it using frames instead of time:

minVal = 0;
maxVal = 200;
dur = 6; // frames
f = timeToFrames(time)
fPrev = Math.floor(f/dur)*dur;
fNext = fPrev+dur;
seedRandom(fPrev,true);
vPrev = random(minVal,maxVal);
seedRandom(fNext,true);
vNext = random(minVal,maxVal);
linear(f,fPrev,fNext,vPrev,vNext)

Dan