Highlighted

expression to switch between fill only and stroke only

Community Beginner ,
Sep 04, 2020

Copy link to clipboard

Copied

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.

squares on a gridsquares on a grid

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

marker lengthmarker length

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

 

 

 

Adobe Community Professional
Correct answer by Rick Gerard | Adobe Community Professional

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:

randomFill.gif

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.

TOPICS
Expressions, FAQ, How to, Scripting

Views

70

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

expression to switch between fill only and stroke only

Community Beginner ,
Sep 04, 2020

Copy link to clipboard

Copied

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.

squares on a gridsquares on a grid

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

marker lengthmarker length

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

 

 

 

Adobe Community Professional
Correct answer by Rick Gerard | Adobe Community Professional

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:

randomFill.gif

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.

TOPICS
Expressions, FAQ, How to, Scripting

Views

71

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 04, 2020 0
Adobe Community Professional ,
Sep 04, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 04, 2020 1
Adobe Community Professional ,
Sep 04, 2020

Copy link to clipboard

Copied

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:

randomFill.gif

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 04, 2020 1
Community Beginner ,
Sep 05, 2020

Copy link to clipboard

Copied

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.

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 05, 2020 0
Adobe Community Professional ,
Sep 05, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 05, 2020 1
Community Beginner ,
Sep 05, 2020

Copy link to clipboard

Copied

Grate. Thank you. I found out a handy solution adding hold keyframes on Offset Turbulence every n frames. Luckily the comp duration is short, my solution works but it isn't linked to markers. I will try to add this expession. I'll let you know

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 05, 2020 0