Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions help with a “loop” to use the same array

  • help with a “loop” to use the same array

    Posted by Alan Tonn on February 24, 2008 at 7:41 am

    i am such a novice at this stuff, but i have a great use for this.

    i have 6 words that i want to repeated show through the entire length of my comp. i know i could easily keyframe it to the text layer i have, but i was hoping i could make it simpler (more complex, but efficient) by using an expression like one i found through this site.

    i am messing with what was this:

    holdTime = 1.0;
    s = “Sheild,Rock,Shelter,Fortress,Refuge,Sanctuary”;
    j = Math.floor(time/holdTime)
    s.split(“,”)[j];

    i tried putting a what i would call a for next loop in it, but i havent been able to get it to work. the problem is that when it gets past j=6 the text becomes undefined. i wonder how i can get it to go back to the first word and start again.

    additionally i am trying to grid this text layer across my entire comp. i have tried some other code for this but the effect isnt quite what i was hoping for. especially since i want to also do it in 3d.

    is there any kind of expression reference material that tells the user the syntax and what a command does?

    for example what is math.floor and what are the parameters i have to feed it?

    any and all help much appreciated.

    Darby Edelen replied 18 years, 2 months ago 3 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    February 24, 2008 at 4:01 pm

    This should make it repeat:

    holdTime = 1.0;
    s = “Sheild,Rock,Shelter,Fortress,Refuge,Sanctuary”;
    j = Math.floor(time/holdTime)%s.split(“,”).length;
    s.split(“,”)[j];

    To make a grid, you could do it with a postion expression that works off the layer’s index, but we’d need to know more about the details of the grid.

    The Math object is part of the JavaScript language. There are lots of JavaScript references – in print and on the web.

    Dan

  • Alan Tonn

    February 25, 2008 at 2:54 am

    Woo Hoo!

    thank you.

    so is the java script in AE exactly the same as javascript out there for the web?

    i do a lot of MS Access programming and it is not exactly the same as Visual Basic .net programming. there are some things that act differently between the VBA and the full Visual Basic.

  • Alan Tonn

    February 25, 2008 at 3:07 am

    i have tried this expression for a grid:

    num_cols=8;
    num_rows=10;

    space_cols=500;
    space_rows=100;

    place_row=Math.ceil((index)/num_cols);
    place_col=Math.ceil((index)-(place_row-1)/num_rows);
    place_compensate=place_row*space_cols*num_cols;

    y=place_row*space_rows-space_rows/2;
    x=place_col*space_cols-space_cols/2-place_compensate;
    [-x,y]

    i placed sliders in place of the static values to see if i could get the results i wanted, but the problem is i would like something a little more fluid and not necessarily “gridish” something that would put lots of copies of the layer in a somewhat random 3d pattern.

    on example of the kind of finished product i am going for is the digits man by eran stern at this tutorial:

    https://library.creativecow.net/articles/stern_eran/Digits_Man1.php

    i want to use the “grid” layer i am trying to create as the “fill” for another layer that i will have in the final comp. basically these words in the array in a “3d random grid” from the previous post will be the fill inside another word.

    keep one thing in mind, i am in AE 7 and cant do the individual character thing that eran does in his tutorial.

    i hope this makes sense. again thanks for any and all help.

  • Darby Edelen

    February 25, 2008 at 6:38 pm

    You can generate a random 2D or 3D position using the random() function if you seed it to be ‘timeless’:


    w = width; //Layer's width
    h = height; //Layer's height

    seedRandom(index, true) //Use the layer's index to seed the random function, don't change over time (timeless)

    r = random([0,0], [w, h]); //Returns a random value between [0,0] and [w,h]

    If you want to animate the positions of the layers you would want to add in some value to this random starting position:


    p = wiggle(3, 10) - value; //'p' is a vector that wiggles with minimum value [-10,-10] and maximum value [10,10]

    r + p

    In the above example the value would wiggle. You could instead get your offset value from slider controls or a point control.

    Darby Edelen
    Designer
    Left Coast Digital
    Santa Cruz, CA

  • Darby Edelen

    February 25, 2008 at 6:44 pm

    [Alan Tonn] “so is the java script in AE exactly the same as javascript out there for the web? “

    Yes… and no. It has all of the same classes and functions that the Javascript you may know from the web does, but it has additional classes, functions and methods defined specifically for use in AE, for example: wiggle(frequency, amplitude).

    It also functions in a somewhat different manner in that the expression is evaluated at every frame of a composition without regard to the previous or next frames, where as other implementations of Javascript may function more like an application with event driven loops.

    All of the syntax is the same, however, and you can even define your own functions within an expression. However, these functions will not be accessible to other expressions even in the same composition (they aren’t “global”) so they will need to be redefined in every expression you want to use them in.

    Darby Edelen
    Designer
    Left Coast Digital
    Santa Cruz, CA

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