The elements in the "sampleImage" expression should be the other way around. It should be point first, and then size. That's why it's not in sync with the control layer. This is the syntax: sampleImage(point, radius = [.5, .5], postEffect=true,t=time) Thanks for the tutorial!
just found this out as well. gave me headaches for quite a while. you should get far more thumbs up. If someone else stumbles upon this and wonders why it's working anyways: It's working in the example above since it's essentially a moving gradient in the controller, so it doesn't matter that much that the sample size is bigger and the sample point is fixed at 1/1 px, but if you want some specific results it will mess everything up. For example if you like to make a radial instead of a linear swipe. Thanks for the, besides that, awesome tutorial ECAbrams.
Awesome tutorial, thanks! One thing to take note though, I tried this and found out that while the code appears to work, the order of the input for sampleImage is wrong. It should be: colour = sourceLayer.sampleImage(samplePoint,sampleSize); samplePoint should come before sampleSize, or else AE will not parse the sampleSize we defined, resulting in it defaulting to an unknown set of large values. In this video the control layer animation is simple, so the error does not affect the result, but for those who wish to use this with more complex animations, the error will result in shape layers behaving wrongly. That said, this code is really useful, thanks again!
+somerlorenzo Goodness thank you! I could not figure out what I was doing wrong! My results were unpredictable at best with anything other than a simple gradient. Your fix solved everything, it works exactly as expected now. Thanks!
That's a one old tutorial out here, but it saved my ass! Many thanks! Btw for those who might need it - to make it work for 3D layers - use this line samplePoint = [transform.position[0],transform.position[1]]; Or this one for separate dimensions samplePoint = [transform.xPosition,transform.yPosition]; Cheers
Dude these last two videos you made are fucking fantastic, need more of this expression type videos, I wanna learn what ever you know in the most creepy way possible
This was especially helpful in creating an animation similar to Apple's dock where items grow and retract when scrolling along. I setup the background control layer to be white in the middle and then 50-60% gray on the sides. Then I could simply layout a row of graphics and as I move them along, they would grow/scale in size according to the gradient. Huge timesaver! Thanks Evan!
"except for that one time when you touched them way too much and it got really awkward, but anyway" that made me giggle way too much. I love After Effects and I love you work.
I don't remember if you pointed this out specifically-- but it's important for that Control Layer to always be opaque. I started the first transition over a transparancy and the expression wasn't working. It would skip right from 0% to 100% when the transition was happening instead of creating that smooth animation. Once I dropped a solid in to start the precomp control layer, perfecto. Thanks for the great tutorial.
This ended up working really well for some dinosaur footprints, walking across the screen. I watched this video yesterday, not sure what I might use it for. Then, today, I needed some dino prints for a project and suddenly remembered this. Thanks!
Hey @ECAbrams Thank yo for this tutorial, I used it with great success about five years ago, but today, I had to use it again for a brief and I am getting a syntax error for the first line of the expression sourceLayer = thisComp.layer("Transition Control 2"); sampleSize = [1,1]; Do you perhaps know if there has been an update to how expressions are treated in After Effects 2022?
Evan, wicked powerful technique you're a magician. I ran into the following error while writing the exact same expression: Bad argument: argument 2 to sampleImage() must be 2 numbers. (Error occurred at line 7) It could be a super simple solution that I don't realize. You are one of the few instructors who actually responds to us ignorant newbies, and for that I thank you.
Well the sampleImage() expects certain things from its arguments or parts. Typically it looks like this: sampleImage(point, radius = [.5, .5], postEffect=true, t=time) So argument 2, the radius, needs to be an array of type 2 [something,something]. Likely you are sending it something of type 1 [something]. It's also telling you your problem is on line 7.
ECAbrams Aha, Silly me. I believe it's because my layers are 3D. Is this possible if I also make the control layer 3D? How would I add the z-dimension? Is it even worth trying
Alex Nye well that's a thing of type 3 [x,y,z] so take what you know and add one more part to it I suppose. But I think sampleImage can only sample in the x,y as related to the frame so... consider that in your calculations. What it outputs to however can be anything your heart desires.
Hi Evan, Saw that you mentioned that this this script would only work in Cs6 or later and just want to let you know that with some tinkering and digging around I managed to get it to work for Cs5. sampleSize = [1,1]; target = thisComp.layer("Control Scale Layer"); rgba = target.sampleImage(transform.position,sampleSize, true, time); hsla = rgbToHsl(rgba); x = hsla[2]*200; [x,x] Also I just wanted to say your videos are great and very helpful. Instead of using large shape layers I decided on using a blurred stroke and trim paths to get the look I wanted. Keep up the awesome work.
Did I say it's only for cs6? I try to warn people that other version may not work correctly but I'm sure the SampleImage thing works for any version with that expression language in it without issue. What part did cs5 not have available from the way it's presented originally?
ECAbrams The SampleImage seemed to work but i was getting some strange animation when using rgb channels. Someone suggested I may try converting and using the luminance to drive the scale. Which seems to work just like your example I just wanted to put it out there if anyone ran into a similar problem.
This is super handy!! I'm going to experiment with this a lot! I did get an error saying it disabled the expression, but when I copy pasted the expression from the description it worked fine again. Weird. Anyway thanks for the tutorial, your way of explaining is clear yet quirky!!
Thanks for another classic! Linked the control layer to a bunch of jpegs and waves them like sugar. I wanted to alter only their horizontal (x) value so I did x=colour[0]*100; y=[100]; [x,y] Now I want them to wave a bit their height (y) as well but proportionally, let's say by a 1:4 ratio. I am very fresh to AE math logic so any suggestion would be welcome. Thanks again!
Thank you once again! Luckily I have this video saved to my 'tutorials' playlist. Just used this on a client project, but instead used the position of the objects to control the scale and transparency based on a static alpha image. Seriously, thank you so much!
Anyone who's wondering about how to manipulate the size of the object created, cause once the expression is online, every object just becomes the same size. For the respective shape layer that is being animated, the size needs to be change in the Contents-Ellipse(for example)- Size. Trying to change the scale won't do anything. Hope it helps. Saw it in a video from Mobox something..
Awesome videos man, love all the content you put out there for people to learn! Revisiting this video 2 year later to ask... How could I add rotation to this expression as well?
Excellent tutorial. I was looking for a way to make custom transitions with an array of shape layers(hexagons) and i was looking for a fast way to animate them all. Thanks
Ok, Evan, this was truly cool!!! I've been following your tutorials and learned many things about expressions. I hope you make more videos about coding in Ae! Respect!
I know Im asking the wrong place but does anybody know a tool to get back into an instagram account? I was dumb lost the account password. I love any tricks you can offer me!
@Cody Nico I really appreciate your reply. I found the site thru google and im trying it out now. Takes a while so I will get back to you later when my account password hopefully is recovered.
This looks promising. How would you translate this to Z-space? I have an image of a tile mosaic and I'd like to have the tiles move closer to and further from the camera in waves. Driving this by a gradient layer seems like a great option.
Hi! How can I transform the position of my layers with that expression? I have 8 images and i need them to drop from the top to the center. Something like we can do with text position animator with squre shape.
Really cool. I have this background which looks like a pattern (lots of objects following the same pattern) and I want to animate them from the center to the edges of the screen (like a radial wipe, if we use your method). The thing is, I already have the animation made and pre composed on each of these objects (which are essentially multiple copies of the same object duplicated to fill the whole background). I just need to play them in this radial fashion. Is there a way to use a similar expression that would use the radial wipe gradient as a control to play my precomposed animation? To use your tutorial as comparsion, I just need to play the Comp once when the radial wipe goes from black to white. In short, instead of controlling the scale property, I need to just play the composition. Not sure If I explained it well, my english very limited.
Great tutorial! Thanks for showing us this very powerful expression and effect. I think this will add some punch to future videos which will really help visual motion. One thing I notice when you paste the code in is that a hypen gets placed in the word "sampleSize" in the brackets and I had to delete that. I thought I'd bring that to everyone's attention just in case.
I'm trying to use this but it seems this expression is not working in the 2017 version. Do you have a workaround? I have literally followed every single step.
This is not working when I want things to expand from the center. Half screen from center to top. And half screen from center to bottom. I created 2 wipes from the center, one going upwards and 1 going downwards. Then the top elements work properly, but bottom ones aren't.
Hello Evan, Thank you for the tutorial! I have applied this technique with text and it appears to work well. I removed the feather of the wipe and set the sample to 0.01,0.01, yet the text still has an "ease" when it scales up despite a fast/sharp color change under the anchor point. Regardless of what I do, I can't gain control over this "ease" and can't find anything in the graph editor. Am I missing something simple? Thank you! ~~G
Hey Evan, thank you for sharing this great technique! I am just wondering why the scaling begins, while the color is still black? I'm trying to animate some objects on with a fractal noise, but all of the elements have almost the same scale, while some areas are still black which should be a scaling of 0%. I hope somebody can help me.
So things to know about colour. 1. Just because it look black it might not be black. Your eyes, monitor calibration, and so on can make even shades of grey look black. 2. The info window can tell you the exact colour value and 3. If the expression is giving you too fast of a scale then you can use math to alter and 4. If you prefer to not use expression changes just work with a control layer in a darker and less contrasting register.
I've read through these comments and am still struggling getting the desire results when applying this to the opacity. I don't have any errors and the basic idea is working, but not the way I want. I'm trying to animate a lot of squares on using the gradient and want the squares to reveal only when there is white or almost all white in the control gradient ramp, but for some reason, even when there is pure black, it's still fading the squares on. Basically, they're coming on too soon. Almost as soon as my white starts entering the frame on the left, the shapes are already all fading on. I really need them to come on only as the white moves across. Thoughts? I'm hoping to not have to figure out a way to do this in cinema 4d. Most of my results in after effects have not been much different than a gradient wipe. The weird thing is that when the gradient animates off, it doesn't do the same thing on the left side of the frame. They animate off fine, but when animating on, they all start fading in too soon no matter feather I have my transition feathered or not.
Heya Evan, Great tutorial and I've used this numerous times and its been a lifesaver. However, I was wondering if there was a method I could use to simplify the expression count. For example I have a grid I made up of 1000 circles using shape layers in AE. because I duplicated the base shape with the expression they all work as expected! This is great, but due to the count of objects it seems like my computer cannot handle and the render time is now much greater.
I worry about that too, I always having trouble finisNice tutorialng anytNice tutorialng I try and create, but I figure if I do a little more each day, it'll get there one
Great tutorial, thanks a lot. I was wondering, what if instead of having an impact on the scale, the gradient had an impact on the percentage of a radial wipe of a circle for example? How the expression should be tweaked to get that ? Thanks !
Thomas Checa well, there is a linear expression in there that remaps value ranges to other value ranges. Make sure the output ranges are appropriate and that the final output is in a format that the new property will understand.
Question, how would I apply this to a shape that's copied with CC Tiler, basically I want the same type of fade from left to right, but since they're one layer, they appear at the same time.
Is it possible to replace Size to Opacity? So that shapes would appear by opacity and not by size? and so that the timing would start only when it the ramp touches the area
my scale didn't change, it started from 80 and stop at 100, is it because image can't be used to do this effect? i merge image and shaped and apply this effect, it doesn't work, by the way im using after effect cc 2017
Do you know of any way to have the control layer drive some animation? Is there a way to have some animation you made proceed along its keyframes based on the gradient information?
at 4:53 at the scale you see a round thing but on the left you see a arrow pointing benead i did not get that how did you do that to get the scale is press s but how do you get that arrow
Hello Evan, thank you very much for the info. I tried using the expression on opacity but it did; t work out. Any ideas why? or what I could do to make it work?
The biggest difference between opacity and scale is that one is a "one part" property like 100, while the other is a two part property like [100,100]. So your final line has to communicate the value the property expects. Does that help explain what's happening?
great tutorial. I have one issue. I want the same animation applied to a bunch of circles of various sizes. The issue is that when I apply the expression/control layer it makes a circle of different proportion the same size as the first shape that used the control layer. completely lost on how to fix this. I even tried to make a second control layer but it seems when i plug in the expression it still converts to the same size.
I found a solution, in case someone else needs it. You need to add clamp expression to it with initial value enabled. Here is the code: sourceLayer = thisComp.layer("yourGradientLayer"); sampleSize = [1,1]; samplePoint = transform.position; colour= sourceLayer.sampleImage(samplePoint,sampleSize); x=colour[0]*100; newX = clamp(x,0,value[0]); newY = clamp(x,0,value[1]); [newX,newY]; ------------------------- What this code does it takes the x value calculated from the colour change, then limits its min/max input. I used it on scale property, so the lowest I want is 0 and max is initial setting e.g. 23%. clamp(x,0,value[0]); will animate the layer and made sure it stops at your initial scale. This lets you set custom scale sizes on objects and animate them with gradient. Hope it makes sense :)
Question: Could you make a control layer using a ramp? I'm a newbie, so that probably sounds pretty stupid but it just crossed my mind while watching this. Regardless, THANKS for all you do for us new folks!
You can. The layer can be anything so long as the effects are all inside the control layer comp. It could be fractal noise, or a video, or anything really.