I am fairly new to writing expressions in Adobe After Effects and need some help. I am trying to write an expression that will generate 300 unique positions for 300 copies of the same image inside an object without having to manually move each image to a new location.
To do that, I created an expression for the first image's position as follows:
I then copied and pasted it 300 times.
The problem with this is that it sets the random position to the entire composition's width and height, whereas I want it to set only to x and y coordinates that are inside the confines of a not-perfectly-shaped map (map of USA) inside the composition. I have tried to mask my object and then write something like this:
x = thisComp.layer("USAMAP").mask("Mask 1").maskPath.width;
y = thisComp.layer("USAMAP").mask("Mask 1").maskPath.height;
But I know this won't exactly work since the object is not a perfect shape. Do I have to define more parameters?
Side question (not as important as my first): When dealing with tons of small images on a very large scale like 300+, is there an easier way to replicate the image without physically copying and pasting? Is there some sort of code that tells After Effects to copy an image and run it `x' amount of times in the background without physically creating the copies? As of now, I've been copying and pasting the image, using sequence layers, and stretching the right tail-end of my timeline for all 300 images. I'm just curious.
Thanks for all the help!
Is there some sort of code that tells After Effects to copy an image and run it `x' amount of times in the background without physically creating the copies?
A layer grid emitter in Particle Playground will do miracles as will do other particle systems. Conversely, a symbol tiled infinitely using Motion Tile and then mapped onto Card Dance will be easy enough. This also saves your problem of how to constrain your symbols - you'd simply use the map as a parameter map for scale or visibility/ opacity. The rest doesn't make much sense. Expressions have no access to mask or shape path data, so you'd have to muck around with sampleImage() to detect the borders and this would need to run in a loop and on every layer no less, so AE would slow down to a crawl, even more so if you wanted to add "smart" code to prevent icons from overlapping. For the time being, go with the particle stuff or otehr methods like pre-composing a cluster of semi-randomly placed icons and using that as a "stamp" in the main comp.
This is really helpful. Thank you so much!