Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Random layer position constrained by another layer’s alpha

  • Darby Edelen

    January 14, 2008 at 5:10 am

    I thought I’d take some time out to let you know that I used a variation of this expression on a recent project. I decided that the toWorld() function wasn’t the best idea, since if you rotate the layer that the trees are supposed to be attached to they will remain upright in world space (they don’t rotate with the ‘island’). Instead I decided that it’s best to leave the point in layer space and parent the ‘tree’ layers to the ‘island’ layer.

    Here is the updated expression:

    if(hasParent){
    l = parent; //The parent of this layer (the 'island')
    w = l.width; //The island layer's width
    h = l.height; //The island layer's height
    thresh = 0.9; //Threshold for alpha value on the island layer

    seedRandom(index, true); //Seed our random numbers and don't update them based on time (timeless)

    p = random([0,0], [w,h]); //'p' is a random point in the layer space of the island layer
    alpha = l.sampleImage(p)[3]; //The alpha value at the point 'p' on the island layer (values range from 0-1)

    //While the alpha value is below our threshold...
    while(alpha < thresh){ p = random([0,0], [w,h]); //Pick a new random point on the island layer alpha = l.sampleImage(p)[3]; //Update the alpha value at the point } [p[0],p[1], 0]; //Returns the point 'p' in the layer space of the parent (island) layer } else value

    If the layer does not have a parent then it defaults to its keyframed values. Once the layers are parented to a layer you can rotate that layer and the layers will behave as you would expect.

    Darby Edelen
    Designer
    Left Coast Digital
    Santa Cruz, CA

Page 2 of 2

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy