Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Coding to randomly rotate a cube on z axis

  • Coding to randomly rotate a cube on z axis

    Posted by Victoria Ellis on June 12, 2006 at 10:01 am

    I am trying to make the rotation on a cube random, but so that it stops on a face for a random (or fixed) amount of time then randomly spins around and stops on another face.

    My coding below makes it rotate randomly, but I have no idea how to make it stop on a face.

    segDur = 3;
    seed = Math.floor(time/segDur);
    segStart = seed*segDur;
    seedRandom(seed,true);
    startVal = random(360+transform.zRotation);
    seedRandom(seed+1,true);
    endVal = random(360+transform.zRotation);
    linear(time,segStart,segStart + segDur, startVal, endVal);

    I did try to do an if loop so that a variable is returned from the rotation value at a specific frame, and when that variable is equal to 90, 180 etc, then a posterizeTime expression is done for a random/fixed about of time, but I didn’t get very far, because I have no idea how to!

    Is there any chance that someone had tried this sort of thing before and can give me some pointers on the code. I have a little coding experience, but hardly any in JavaScript.

    Also, does anyone know of an AE specific JavaScript book that I can get hold of to make scripting a bit easier?

    Many thanks,
    Victoria

    Victoria Ellis replied 19 years, 11 months ago 3 Members · 3 Replies
  • 3 Replies
  • Ryan Hill

    June 12, 2006 at 3:04 pm

    Maybe create a posterized random value that is always at 90-degree angles. Then apply a smooth function to that value, averaging an amount of time that you want it to take to turn to a new side.

    I can get into more details later.

  • Colin Braley

    June 12, 2006 at 4:15 pm

    Try his expression for z-rotation:

    //Begin expression
    segMin = .3; //minimum segment duration
    segMax = .7; //maximum segment duration
    //–
    list = [0, 90, 180, 360];
    minVal = 0;
    maxVal = 3;
    //–
    end = 0;
    j = 0;
    while ( time >= end){
    j += 1;
    seedRandom(j,true);
    start = end;
    end += random(segMin,segMax);
    }
    endVal = list[Math.round( random(minVal,maxVal))];
    seedRandom(j-1,true);
    dummy=random(); //this is a throw-away value
    startVal = list[ Math.round(random(minVal,maxVal))];
    ease(time,start,end,startVal,endVal)
    //–end expression

    I just took a sample from Dan’s site, http://www.motionscript.com and modified it a bit. And as for your question asking wheteher there are any books on javascript for AE, the answer is no. (Well at least not until someone can convince Dan Ebberts to write one) If you want some websites to learn expressions/scripting from just search the archives and you can find some links.
    ~Colin

    ~Colin Braley

  • Victoria Ellis

    June 12, 2006 at 6:08 pm

    Superb! That is exactly what I needed. Thank you so much!!
    Victoria

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