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
-
Moniek Van adrichem
November 12, 2015 at 10:39 pmHi Dan,
I was wondering if it would be possible to make it so that the squares all randomly get a color and duration assigned (which is different for each square). But that you can set the colors and range for the duration in a Control null, so that you can easily adjust that.
Thanks a lot!
Moniek
-
Dan Ebberts
November 13, 2015 at 12:40 amSomething like this maybe:
ctrl = thisComp.layer(“Control”);
c1 = ctrl.effect(“Color Control”)(“Color”);
c2 = ctrl.effect(“Color Control 2”)(“Color”);
c3 = ctrl.effect(“Color Control 3”)(“Color”);
c4 = ctrl.effect(“Color Control 4”)(“Color”);
colors = [c1,c2,c3,c4];
minDur = ctrl.effect(“Min Duration”)(“Slider”);
maxDur = ctrl.effect(“Max Duration”)(“Slider”);
seedRandom(index,true)
segDur = random(minDur,maxDur);
easeTime = .2;
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
-
Moniek Van adrichem
November 15, 2015 at 10:57 pmThanks so much, that works! So now I wanted to put the color values in the source text of a textlayer, so I could later decide to add or delete a color. Problem is that I cannot get my head around how to do this…
-
Dan Ebberts
November 16, 2015 at 2:07 amIt depends a lot on how you want to represent the colors.
Dan
-
Moniek Van adrichem
November 16, 2015 at 7:24 amI thought the most convenient way would be to use an array of arrays like this:
[[141,203,235,255]/255,
[164,213,239,255]/255,
[205,219,143,255]/255]But if its easier to use the 0-1 values that’s fine too 🙂
-
Dan Ebberts
November 16, 2015 at 5:19 pmIf your text layer text is like this:
[[141,203,235,255]/255,[164,213,239,255]/255,[205,219,143,255]/255]
then something like this should give you your color array:
colors = eval(thisComp.layer(“your text layer”).text.sourceText.value);
Dan
-
Moniek Van adrichem
November 16, 2015 at 6:54 pmThat’s what I thought as well, but somehow that gives this error (which refers to the line of idx1=Math.floor(random(colors.length))):
property or method named “length” in Class “Number” is missing or does not exist. It may have been renamed, moved, deleted, or the name may have been mistyped.
The weird thing is that I don’t get this error when putting the numbers directly in the expression.
ctrl = thisComp.layer("colours");colors=eval(ctrl.text.sourceText.value);
minDur = ctrl.effect("minDuration")("Slider")
maxDur = ctrl.effect("maxDuration")("Slider");
seedRandom(index,true)
segDur = random(minDur,maxDur);
easeTime = ctrl.effect("easeDuration")("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]) -
Moniek Van adrichem
November 16, 2015 at 7:29 pmWhen evaluating the expression in another Source Text I found that somehow the square brackets which define the color-arrays are removed when using
ctrl = thisComp.layer(“colours”);
colors=ctrl.text.sourceText.value;So that might be the problem
-
Moniek Van adrichem
November 16, 2015 at 8:08 pmWoohoo! I figured it out, the problem was that you get a string from the Source Text, so you first need to convert that to an Array. Also I had to make a workaround on the fact that the square brackets in the middle get removed. I guess there’s a more elegant solution, but this works 😀
ctrl = thisComp.layer("colours");colorstring=ctrl.text.sourceText;
colors=colorstring.split(",");
minDur = ctrl.effect("minDuration")("Slider")
maxDur = ctrl.effect("maxDuration")("Slider");
seedRandom(index,true)
segDur = random(minDur,maxDur);
easeTime = ctrl.effect("easeDuration")("Slider");curSeg = Math.floor(time/segDur);
t = time%segDur;
seedRandom(curSeg,true);
idx1 = (Math.floor((random(colors.length))/4))*4;
seedRandom(curSeg-1,true);
idx0 = (Math.floor((random(colors.length))/4))*4;
color0 = colors.slice(idx0,(idx0+4));
color1 = colors.slice(idx1,(idx1+4));
ease(t,0,easeTime,color0,color1) -
Jason Jantzen
May 24, 2016 at 4:07 amHey Dan, this helped solve a huge headache I was dealing with tonight, but now I’m wondering if it’s possible to randomize the segment time for each square? Thank you for all your amazing help!
Jason Jantzen
vimeo.com/jasonj
Reply to this Discussion! Login or Sign Up