Activity › Forums › Adobe After Effects Expressions › Random change to specific color
-
Random change to specific color
Shannon Copfer Brace replied 5 years, 9 months ago 12 Members · 30 Replies
-
Dan Ebberts
May 24, 2016 at 4:26 amIf I understand what you’re asking, I think you could just replace this:
segDur = 2;
with this:
minDur = 1.5;
maxDur = 2.5;
seedRandom(index,true);
segDur = random(minDur,maxDur);Dan
-
Jason Jantzen
May 24, 2016 at 1:43 pmI thought it would be something like that based on your Random Motion examples on your site. I just can’t speak expressions well enough to make it work. You are the best, Dan! Thanks!
Jason Jantzen
vimeo.com/jasonj -
Ohad Sitton
September 28, 2016 at 2:38 pmhi dan thaks for a great tip. i was trying to use it but could not get a linear color transition whit out easing between colors. i copy paste the last line and replace that to linear as you suggeted but steel get the same issue with as the colors are easing from one to another.
any suggestions?
thanks. -
Emil Stefanow
August 28, 2018 at 7:30 amWow, Dan!
This expression is amazing! Thanks so much! For my purposes I have even defined over 15 colors!I have inserted it onto the Fill Effect (Color) of a Solid in a Comp named “Comp A”.
I also have Comp B, Comp C, Comp D, Comp E and Comp F with the same setup (Solid with the same expression mentioned). The expression works like a charm.Is it howerer possible to tweak the expression(s) so that the random colors are NEVER the same at any given frame? The use the same pre-defined colors but are never the same. With seedRandom it probably doesn’t work, because it’s still randomness.
Thank you!
EmilC1=[255,255,255,255];
C2=[252,249,245,255];
C3=[208,209,203,255];
C4=[225,241,236,255];
C5=[234,204,182,255];
C6=[251,243,234,255];
C7=[48,39,37,255];
C8=[226,236,176,255];
C9=[98,150,54,255];
C10=[253,210,121,255];
C11=[111,33,73,255];
C12=[144,26,126,255];
C13=[118,72,152,255];
C14=[242,134,0,255];
C15=[235,90,55,255];
C16=[174,35,43,255];
C17=[60,28,20,255];
colors = [C1/255,C2/255,C3/255,C4/255,C5/255,C6/255,C7/255,C8/255,C9/255,C10/255,C11/255,C12/255,C13/255,C14/255,C15/255,C16/255,C17/255];
easeTime =comp("Comp 1").layer("CTRL").effect("easeTime")("Slider");
segDur = comp("Comp 1").layer("CTRL").effect("segDur")("Slider");curSeg = Math.floor(time/segDur);
t = time%segDur;
seedRandom(curSeg,true);
idx1 = Math.floor(random(colors.length));
seedRandom(curSeg-1,true);
idx0 = Math.floor(random(colors.length));
ease(t,0,easeTime,colors[idx0],colors[idx1]) -
Dan Ebberts
August 28, 2018 at 4:10 pmI think this will work:
C1=[255,255,255,255];
C2=[252,249,245,255];
C3=[208,209,203,255];
C4=[225,241,236,255];
C5=[234,204,182,255];
C6=[251,243,234,255];
C7=[48,39,37,255];
C8=[226,236,176,255];
C9=[98,150,54,255];
C10=[253,210,121,255];
C11=[111,33,73,255];
C12=[144,26,126,255];
C13=[118,72,152,255];
C14=[242,134,0,255];
C15=[235,90,55,255];
C16=[174,35,43,255];
C17=[60,28,20,255];
colors = [C1/255,C2/255,C3/255,C4/255,C5/255,C6/255,C7/255,C8/255,C9/255,C10/255,C11/255,C12/255,C13/255,C14/255,C15/255,C16/255,C17/255];
easeTime =comp("Comp 1").layer("CTRL").effect("easeTime")("Slider");
segDur = comp("Comp 1").layer("CTRL").effect("segDur")("Slider");t = 0;
seedRandom(index,true);
idx0 = Math.floor(random(colors.length));
while (t <= time){
idx1 = (idx0 + (Math.floor(random(colors.length-1))+1))%colors.length;
t += segDur;
if (t > time) break;
idx0 = idx1;
}
ease(t,0,easeTime,colors[idx0],colors[idx1])
Dan
-
Dan Ebberts
August 28, 2018 at 8:52 pmI forgot about the ease. The last line should probably be like this:
ease(time,t-segDur,t-segDur+easeTime,colors[idx0],colors[idx1])
Dan
-
Shannon Copfer Brace
August 17, 2020 at 5:16 pmHi there! SUPER beginner here trying to piece this together for a work project (my usual job is not motion graphics, and I haven’t used AE since 2009-ish, and it was for simple titles!). Thank you in advance for your patience.
Dan, your code is clear. I have two questions:
First, a very basic/stupid question: I have about 60 small layers/objects I’m animating, and I have their motion paths defined. I’d like to add in this color randomization for part of the animation. So question one is: Where do I put this code? Does it need to be placed on each layer?
Second, I’m testing it on one layer and I’m getting an error both in legacy and in javascript expressions engine. The two (different ) error screenshots are below. Any ideas?
– Legacy: 14272_screenshot20200817at12.58.44pm.png.zip
– Javascript: 14273_screenshot20200817at12.59.02pm.png.zipThank you so much for your help!
colors = [60,64,131,255]/255,
[45,162,213,255]/255,
[130,191,156,255]/255,
[221,222,226,255]/255];
easeTime = .2;
minDur = 1.5;
maxDur = 2.5;
seedRandom(index,true);
segDur = random(minDur,maxDur);curSeg = Math.floor(time/segDur);
t = time%segDur;
seedRandom(curSeg,true);
idx1 = Math.floor(random(colors.length));
seedRandom(curSeg-1,true);
idx0 = Math.floor(random(colors.length));
ease(t,0,easeTime,colors[idx0],colors[idx1]) -
Dan Ebberts
August 17, 2020 at 5:33 pmThe expression needs to go on a color property (Fill color maybe?) and each property will need its own expression. Depending on how you have things set up, you might be able to save a lot of time by applying the expression to one property, selecting that property, Edit > Copy Expression Only, select all the other layers, Edit > Paste.
It looks like you left out the opening square bracket:
colors = [[60,64,131,255]/255,
Dan
-
Shannon Copfer Brace
August 17, 2020 at 6:38 pmWow! Thank you so much Dan for your fast reply; you were exactly right and while I wasn’t able to copy and paste them all at once it was still okay. It works! Thank you again!
-
Shannon Copfer Brace
August 19, 2020 at 2:50 pmHi Dan! Thank you again for your help this week and your super quick reply.
Follow-up question: is there a way to get the object to end its wiggle in a specific pre-set position, rather than stopping wherever it is mid-wiggle at the end of the wiggle time frame? (e.g. I want the shapes to wiggle on their path until they get to their destination and then stop specifically into position).
Reply to this Discussion! Login or Sign Up