2 Replies Latest reply on Dec 29, 2016 1:35 PM by nestorm84398713

    Using expressions to define x and y positions inside an object

    nestorm84398713

      Hello!

       

      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:

      seedRandom(3,true);

      random([thisComp.width,thisComp.height])

       

      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:

       

      seedRandom(9,true);

      x = thisComp.layer("USAMAP").mask("Mask 1").maskPath.width;

      y = thisComp.layer("USAMAP").mask("Mask 1").maskPath.height;

      random([x,y])

       

      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!

        • 1. Re: Using expressions to define x and y positions inside an object
          Mylenium Most Valuable Participant

          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.

           

          Mylenium

          • 2. Re: Using expressions to define x and y positions inside an object
            nestorm84398713 Level 1

            This is really helpful. Thank you so much!