Random Flicker Opacity

Creates a flicker effect that switches between 0 and your set opacity. You control how often it flickers using a frame-based speed setting.

Author:
Denis Stefanides
Category:
Random

Expression Code

speed = 10; // how many frames each flicker lasts
maxOpacity = value; // uses whatever opacity you manually set on the layer

n = Math.sin(time / thisComp.frameDuration * (1 / speed) * Math.PI);
n <= 0 ? 0 : maxOpacity;
js

Where to Apply

Apply this expression to any property with a stopwatch, but it’s usually used on:

Transform > Opacity
Select your layer → press T for Opacity → Alt + Click the stopwatch → paste the code.


How It Works

  1. speed = 10;
    This sets the flicker rate. It's telling the expression to go through a full flicker cycle every 10 frames. If you want it to flicker faster, you can use a smaller number like 3 or 5. For slower flickers, try 15 or 20.

  2. maxOpacity = value;
    This just grabs whatever opacity value you set for the layer. If your layer is set to 70%, then that becomes the "on" value when the flicker is active. You don't need to hardcode the number—it automatically uses the layer's opacity setting.

  3. n = Math.sin(time / thisComp.frameDuration * (1 / speed) * Math.PI);
    This is the core of the flicker. Here's how it works:

    • time / thisComp.frameDuration converts the current time into a frame number.

    • (1 / speed) turns your speed value into a frequency.

    • Multiplying by Math.PI shapes the sine wave so that it completes a clean up-down cycle over the number of frames you picked.

    • The result is a wave that goes above and below zero in a regular rhythm, based on frame count.

  4. n <= 0 ? 0 : maxOpacity;
    This is a simple condition:

    • If the sine wave is zero or negative, the opacity is set to 0.

    • If it’s positive, the opacity jumps to your set value (like 70).
      So the layer flickers back and forth between off and on in a predictable loop.

Frequently asked questions

How do I use the expression on this page?

Just copy the full expression code from the top of this page. Then Alt-click (or Option-click on Mac) the stopwatch on the property you want to animate. Paste the code into the editor and that's it. If you’re not sure which property to use, check the "Where to Apply" section above.

The expression isn’t working. What should I check?

First, make sure your project is using the JavaScript engine (go to File > Project Settings > Expressions). Also double-check for missing characters, and see if the code requires parenting a layer. If so, there will be a comment in the code explaining what needs to be connected.

I’m not sure what the expression does. Where can I learn more?

Take a look at the "How It Works" section on this page. It explains each part of the expression in plain language so you can understand how everything works together.

Can I customize how the expression behaves?

Yes, absolutely. Most expressions include easy-to-edit variables near the top and comments that guide you on what to change. You can also link sliders or checkboxes using Expression Controls if you want more control in the timeline.

Can I apply this to other properties too?

Yes, you can use it on any property with a stopwatch. That includes Position, Scale, Opacity, and also effect settings like Blur or Tint.

Will it work in comps with different frame rates or sizes?

In most cases, yes. These expressions are designed to adapt to your comp’s resolution and frame rate. If anything specific needs adjusting, it’ll be noted in the code or in the "How It Works" section.