Creative COW SIGN IN :: SPONSORS :: ABOUT US :: CONTACT US
ADOBE AFTER EFFECTS: ForumAE BasicsAE ExpressionsTutorialsArticlesPodcastsMotion GraphicsTrainingCinema 4D

Re: Random layer position constrained by another layer's alpha

Cow Forums : Adobe After Effects
FAQ   •   VIEW POSTS   •   ADD A NEW POST   •   SEARCH   •   CHANGE FORUM
Return to Posts Index   •   Read Entire Thread   •   Reply To This Post


cowcowcowcowcow
Re: Random layer position constrained by another layer's alpha
by Darby Edelen on Jan 7, 2008 at 6:07:19 am

The way I would approach this is by looping through random points on the layer, sampling its alpha and stopping the loop when the sample point is over a threshold of alpha value.

I should note that I haven't error checked this code at all, I don't have AE on this computer so I'm writing this from memory (and the online documentation) =)


l = thisComp.layer("Island.psd"); //The 'island' layer
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)[4]; //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)[4]; //Update the alpha value at the point
}

l.toWorld(p); //Transforms the point 'p' from layer space to world space



This will return a point in 3D space that should correspond to a random point on the island layer that has an alpha value greater than or equal to 0.9 (0 is fully transparent, 1 is fully opaque), so make sure you have your anchor point on your tree layer set to the base of the trunk (where it will meet the island) and apply this expression to each tree's position property.

Let me know if there are problems with this code, I can check it tomorrow for errors.

Darby Edelen
Designer
Left Coast Digital
Santa Cruz, CA


Return to Posts Index   •   Read Entire Thread   •   Reply To This Post


Current Message Thread:


Related Threads:
Random layer position constrained by another layer's alpha



Note: If you are a registered user and you do not see your name and email in the two respective fields above, you may reset your account cookies by clicking here. Your post will not be accepted if the name and email provided above are not currently registered in our database.

Name
E-Mail Address
Subject
E-Mail me when someone responds
Just This Message   Entire Thread   None  


Message                Add Bold Tag To Message (JavaScript required)

To put any item inside this tag:

1. Highlight the desired text
2.Click this buttonAdd Italic Tag To Message (JavaScript required)

To put any item inside this tag:

1. Highlight the desired text
2.Click this buttonAdd Underline Tag To Message (JavaScript required)

To put any item inside this tag:

1. Highlight the desired text
2.Click this buttonAdd Image Link Tag To Message (JavaScript required)

To put any item inside this tag:

1. Highlight the desired text
2.Click this buttonAdd URL Link Tag To Message (JavaScript required)

To put any item inside this tag:

1. Highlight the desired text
2.Click this button

Note: The following characters are HTML command characters, and may cause parts of your post to disappear, if not used correctly: < > &. To include any portion of the post in your response, highlight the desired text and hit the "Q" key. For more on how to post, click here.


Add your message signature


 


Note: By clicking "Post Direct" button above, you are agreeing to the Creative Cow's Code of Conduct.



FORUMSTUTORIALSMAGAZINEDVDsBOOKSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

© CreativeCOW.net All rights are reserved.

[Top]