Skip to main content
New Participant
September 4, 2020
Answered

expression to switch between fill only and stroke only

  • September 4, 2020
  • 2 replies
  • 2865 views

Hi all,

i'm trying to animate squares on a grid. They should switch between fill on and off and as consequence stoke shloud do the opposite. If fill is on then stoke is off.

At the end this should be controlled by the length of a marker and randomly continue,

If the marker is 5f long then the triks should happen randomly after Nx5 frames where N= is a random value.

How can i do this? 

Thanks

 

 

 

This topic has been closed for replies.
Correct answer Rick Gerard

I would approach this kind of project using an animated fractal noise layer to generate random color values, then sample the colors under an array of shape layers and tie the fill stroke opacity to the color sample and the fill opacity to the stroke opacity with expressions. This project took me about 5 minutes to setup:

Here are the expressions:

 

// Stroke Opacity
target = thisComp.layer("Fractal Noise");
smpl = target.sampleImage(position, radius = [.5, .5], postEffect = true, t = time);
lumaVal = (smpl[0] + smpl[1] + smpl[2]) / 3;
if (lumaVal < .5)
	0;
else
	100;

// Fill Opacity
strokeV = content("Rectangle 1").content("Stroke 1").opacity;
if (strokeV < 50)
	100;
else
	0;

 

 The only changes I made to fractal noise were to increase the contrast to 140, multiply time by 180 so every 2 seconds I got a full revolution of evolution and set loop evolution to on. The speed of the evolution changes the speed of the opacity changes.

 

I think this approach is going to be easier than using a layer marker value at time then randomize the switching. If you really want to use random number generators you'll have to do a lot more than set random(5, 10) because that would generate a new value between 5 and 10 every frame. 

 

Overlaying an animated gradient on the Fractal Noise layer would allow you to have all the rectangles be on and then have them start animating as you animate the gradient overlay. There are lots of possibilities. Here's a project file for you to play with.

2 replies

Rick GerardCorrect answer
Adobe Expert
September 5, 2020

I would approach this kind of project using an animated fractal noise layer to generate random color values, then sample the colors under an array of shape layers and tie the fill stroke opacity to the color sample and the fill opacity to the stroke opacity with expressions. This project took me about 5 minutes to setup:

Here are the expressions:

 

// Stroke Opacity
target = thisComp.layer("Fractal Noise");
smpl = target.sampleImage(position, radius = [.5, .5], postEffect = true, t = time);
lumaVal = (smpl[0] + smpl[1] + smpl[2]) / 3;
if (lumaVal < .5)
	0;
else
	100;

// Fill Opacity
strokeV = content("Rectangle 1").content("Stroke 1").opacity;
if (strokeV < 50)
	100;
else
	0;

 

 The only changes I made to fractal noise were to increase the contrast to 140, multiply time by 180 so every 2 seconds I got a full revolution of evolution and set loop evolution to on. The speed of the evolution changes the speed of the opacity changes.

 

I think this approach is going to be easier than using a layer marker value at time then randomize the switching. If you really want to use random number generators you'll have to do a lot more than set random(5, 10) because that would generate a new value between 5 and 10 every frame. 

 

Overlaying an animated gradient on the Fractal Noise layer would allow you to have all the rectangles be on and then have them start animating as you animate the gradient overlay. There are lots of possibilities. Here's a project file for you to play with.

New Participant
September 5, 2020

Here we go...this is what i need. Thank you. I knew this techniqe but it didn't cross my mind. 

I use a tool to control shape and stroke colors that generates animation based on markers lenght so it wuold be nice to use them in order to be able to manage the timing. So every 5f (markers lenght) the magic happens but instead whit Fractal noise it can't be done.

 

Adobe Expert
September 5, 2020

The project file I send has an animated shape layer over the fractal noise so that the squares don't start animating until the shape layer passes. Check it out. It may be able to give you what you want.

 

You could also add another if statement to the bottom of the Stroke expression so that a specific layer would not start responding to the fractal noise layer until after the time of the first layer marker. 

 

target = thisComp.layer("Fractal Noise");
smpl = target.sampleImage(position, radius = [.5, .5], postEffect = true, t = time);
lumaVal = (smpl[0] + smpl[1] + smpl[2]) / 3;
if (lumaVal < .5)
	v = 0;
else
	v = 100;

if (time < marker.key(1).time)
	0;
else
	v;

 

This expression would throw an error if there was no layer marker. That can also be fixed, but as it stands you could stop any layer from animating until the first marker has been reached. Using Fractal Noise is still by far the easiest way to control the timing of random changes.

Mathias Moehl
Adobe Expert
September 4, 2020

In shape layers, you can control the opacity of strokes and fills independently - and apply expressions to them. Hence, you can link the opacity of the Fill to the Opacity of the Stroke using the pick whip.

This gives you an expression like

content("Rectangle 1").content("Stroke 1").opacity

Now add a "100-" at the beginning:

100-content("Rectangle 1").content("Stroke 1").opacity

 

Now, whenever you set the stroke opacity to 100, the fill opacity goes to 0 and vice versa.

 

I don't fully understand how you want to trigger the stroke/fill using the markers, but in general this means you need to apply another expression to th stroke opacity next that looks at the most nearby marker and sets the opacity to 0 or 100, respectively to hide or show the stroke.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects