ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Random Opacity Change (lights on and off skyline)

FAQ   •   VIEW ALL
 Random Opacity Change (lights on and off skyline) on Mar 10, 2018 at 4:21:47 pm

Hi Guys and Girls,

For a project to bring a Skyline to live, i have several hunderd window layers which should turn on and off in a random pattern, like people are coming and going.
For this I would like the opacity to go 100 or 0 at random moments. Now I have tried and searched, but now it's just guessing, so I could use some help from the expression wizards. NOTE: I am a beginner with expressions.
The composition exist out of a master composition, with a Precomp for the windows, and in that precomp multiple precomps to seperate the buildings.

So I found this Expression from Dan at: https://forums.creativecow.net/thread/227/24412
seedRandom(index,true);
t = random(thisComp.duration);
ease(time,t,t+thisComp.frameDuration*24,0,100)

Which works great, make a perfect pattern, because each lights has a unique moment of going on, and you can even make them fade. Or off if you change the last piece of the code to:

seedRandom(index,true);
t = random(thisComp.duration);
ease(time,t,t+thisComp.frameDuration*24,100,0)

My problem is that the composition is 30min long, so lights should go On and Off more than 1 time. So I tried the following:

holdTime = 6; //time to hold (seconds)
seed = Math.floor(time/holdTime);
seedRandom(seed,true);
Math.round (random())*100

Which works but it's a static interval, so which window is going on or off is random. But they change together, therefore it looks unnatural. So then I tried to make the interval random, so each window would have unique moment of going on or off like in the first expression, and made this:

seedRandom(Math.floor(time/200), timeless = true);
holdTime = random(100,200);
seed = Math.floor(time/holdTime);
seedRandom(seed,true);
Math.round (random())*100

The problem is now that the lights indeed go on and off at random moments if i look at the precomps of the building, but when rendered out together, it seems they wait for a minute and then change randomly for half a minute and then wait again, etc. I tried altering the first Seedrandom number and the Holdtime = Random numbers with sliders to look for something that worked, faster and slower worked, but the waiting problem remains.

So if someone would share some thoughts on this that would be great. I look for an expression that will make the windows turn on and off a random moments, with random interval, fading is nice but not necessary. It would be great to be able to control how fast the blink, so it looks natural on a skyline and not in a disco.

Thanks in advance and kind regards,

Reynoud
Studio NOUD (Netherlands)

 Re: Random Opacity Change (lights on and off skyline)on Mar 12, 2018 at 1:36:00 pm

I think the problem is, that every "window" get the same seed during your calculation. Same seed means same intervall. Try to add a number to your seed that is unique but did not change during time. So lets add "+index" in this line seedRandom(seed+index,true);

This means that the index number of this layer will be added to your seed. Duplicating the layer means, that the next layer have a different number added to the seed. You can put "+1" or "+2" here manually of course. I'll hopes that is a solution.

```seedRandom(Math.floor(time/200), timeless = true); holdTime = random(100,200); seed = Math.floor(time/holdTime); seedRandom(seed+index,true); Math.round (random())*100```

 Re: Random Opacity Change (lights on and off skyline)on Mar 13, 2018 at 3:07:59 pm

Hi Matthias,

That's a great idea! Worked like a charm. This solves a big part in the interval problem. Thank you very much.
Also found out this morning that in de the first seedRandom(Math.floor(time/200) the number 200 should be the same amount of seconds as the composition, otherwise there will still be intervals of multiple layers changing at the same moment.

```seedRandom(Math.floor(time/200), timeless = true); //200 should be comp duration holdTime = random(100,200); seed = Math.floor(time/holdTime); seedRandom(seed+index,true); Math.round (random())*100```