Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Making an object change color every 90 degrees

  • Making an object change color every 90 degrees

    Posted by David Mathis on November 24, 2013 at 6:41 am

    I would like to animate a star shape and have it change color every 90 degrees. Would it be necessary to convert to radians first? If my understanding is correct 90 degrees is the equivilant of 1/4 radian. The first part of the expression I am not positive about. That would be converting degrees to radians so any help is very much appreciated.

    Dan Ebberts replied 12 years, 8 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    November 24, 2013 at 8:00 am

    You only need to use radians if you use JavaScript’s trig functions. For what you want to do, degrees should be fine. This will increment every 90 degrees

    Math.floor(transform.rotation/90);

    You didn’t mention how you wanted to relate it to color though.

    Dan

  • David Mathis

    November 24, 2013 at 5:38 pm

    Thank you. As far as the color scheme would go I would want the color to be as follows:

    At a value of 90 degrees red
    At a value of 180 degrees blue
    At a value of 270 degrees green
    At a value of 360 degrees yellow

    I want to the process to start over again after the rotation is greater than 360 degrees, if possible. I can get the the expression to work until it goes past 360 degrees then it stays yellow.

    There are two expressions below. One is a slider that and the other is for the color.

    Probably something I am overlooking is simple. Thank you again for your response.

    For the slider control:

    r = transform.rotation
    if (r<0) r*-1
    else r

    This expression will be used to return a positive value even though the rotation is not. This expression will be to create the next expression.

    Color expression:
    Math.floor(transform.rotation/90)
    r = effect("Slider 1")("Slider");
    if (r>90 && r<180) [255,0,0,1]
    else if (r>180 && r<270) [0,255,0,1]
    else if (r>270 && r<360) [0,0,255,1]
    else [255,255,0,1]

  • Dan Ebberts

    November 24, 2013 at 6:10 pm

    This should work (with positive or negative rotation values):

    colors = [[1,0,0,1],[0,0,1,1],[0,1,0,1],[1,1,0,1]]; // red, blue, green, yellow
    idx = Math.floor(Math.abs(transform.rotation)/90)%colors.length;
    colors[idx]

    Dan

  • David Mathis

    December 1, 2013 at 7:07 pm

    Thank you! The expression worked but now I have another question. I would like to add a check box to determine if I want it to change color or have the color set to whatever I choose with the box not checked. I tried the expression below but kept getting an error message.

    change = effect("Change Color")("Checkbox")'

    if (change == true): {
    colors = [[1,0,0,1],[0,0,1,1],[0,1,0,1],[1,1,0,1]]; // red, blue, green, yellow
    idx = Math.floor(Math.abs(transform.rotation)/90)%colors.length;
    colors[idx]
    } else {
    value }

  • Dan Ebberts

    December 1, 2013 at 7:17 pm

    I think there are just a couple of typos. This should work:


    change = effect("Change Color")("Checkbox");

    if (change){
    colors = [[1,0,0,1],[0,0,1,1],[0,1,0,1],[1,1,0,1]]; // red, blue, green, yellow
    idx = Math.floor(Math.abs(transform.rotation)/90)%colors.length;
    colors[idx]
    }else
    value

    Dan

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