Activity › Forums › Adobe After Effects Expressions › Opacity Wiggle Checkbox Control
-
Opacity Wiggle Checkbox Control
Posted by Wyclef Chron on December 1, 2014 at 11:49 pmHey, I’m wanting to turn opacity on and off randomly and am using effect
("Checkbox Control")("Checkbox")*100on the opacity and then the checkbox on/off control withwiggle(2,20)but I’d like the off to be a defined time or narrower time that opacity remains off. Wondering how I can adjust things so the wiggle for off is either a defined time or a much narrower range. Thanks.("Checkbox Control")("Checkbox")*100wiggle(2,20)
David Conklin replied 11 years, 5 months ago 2 Members · 5 Replies -
5 Replies
-
David Conklin
December 1, 2014 at 11:59 pmUsing the random() function you can generate a normalized value between 0 and 1. You can then check this random number against a number you set. For instance:
var r = random();
var percentage = .8;
if(r > percentage) {
1;
} else {
0;
}
In the above example, picking .8 means that anything under .8 will turn the checkbox off, anything above will turn it on. Since the likelihood of getting a number between 0-1 less than .8 is 80%, you can control how frequently each state occurs. If you want it to be off 20% of the time you could change the percentage to .2, if you wanted it off 50% if the time you could use .5.
If you want smoother random numbers, try using a gaussian random instead of the regular random.
Good luck!
David Conklin
Motion Designer -
Wyclef Chron
December 2, 2014 at 12:39 amsomething like this could maybe work but I guess I’m still left with the same problem in that when it’s checked off I am still looking to control the length of time it’s off. with wiggle there was kind of a wide range of time based and with random it’s sort of like a short flicker. i’m basically trying to make an eye blink here randomly… my original wiggle was pretty close but the blinks were too long. this script now the blinks are a quick flickr. i trying to make a more natural random wiggle eye blink… not a spastic over-caffinated freak.
-
David Conklin
December 2, 2014 at 3:24 pmYou could impose some sort of frame checker to space out these ‘blinks’ in the code below, I use the modulo operator, which essentially does division and returns the remainder, meaning 10%3 = 1, since 3 goes into 10 evenly 3 times with 1 left over.
Using this you can tell the expression to only have a chance to be turned on when a frame is a multiple of a specific number. For example, if you enter ’25’ into the check frame var, the random expression will only work on frames 25, 50, 75, 100, 125…. if you changed it to 33 it would only work on 33, 66, 99, 132, etc.
The random expression is the same here.
The gist of this expression is that every 25th frame has an 20% chance of being on. Increasing the checkFrame variable gives less frames the chance to be turned on, increasing the prob variable will increase the chance that each checked frame will be on.
Give this a go and let me know.
//get the frame number.
var frameNum = time/thisComp.frameDuration;//remove decimals for not-even frame
//rates like 29.97
frameNum = frameNum.toFixed(0);//number to check against. If frame number is
//divisible by this number, it has a chance
//to be turned on.
var checkFrame = 25;//probability that that the random check
//will pass (% on)
var prob = .2;//if we're on a frame which is a multiple
//of check frame (25, 50, 75, 100, 125...)
if(frameNum%checkFrame == 0){
//have an 20% chance to be on.
(gaussRandom() < prob) ? 100 : 0;
} else {
//not on a checked frame, off.
0;
}David Conklin
Motion Designer -
Wyclef Chron
December 2, 2014 at 5:19 pmHmmm… that script didn’t work for me. Should < be <?
So there is no way to do something like the if else thing with 1 and 0 where else if 0 then 0 + time*.25second or something? Seems like all I’m wanting to do is control the off time… then I can slow down the random speed to make things more natural.
-
David Conklin
December 2, 2014 at 7:49 pmYes, for some reason the code here formatted the less than sign improperly. You can just fix that on line 17 and it works fine.
If you are looking for a ‘slower’ random, your best best would be to explore the ‘noise’ function, rather than random. Random, and gaussRandom, are going to be calculated each frame – there’s no way to make them generate less often other than defining which frames they should be active on, as we did above.
The noise() function, on the other hand, takes a custom input and the differences in the output correlate to the differences in the inputs. For example:
noise(1) is much closer to noise(1.1) than noise(100).
Using this, you can create much more similar values from the noise function by feeding it values that are very close to one another. For instance:
noise(time / 10) or noise(time/100000)
Keep in mind, though, that while this will have longer periods of ‘off’, it will also have longer periods of ‘on,’ so I’d suggest combining this with some of what we did above to keep your ‘blinks’ short.
Good luck.
David Conklin
Motion Designer
Reply to this Discussion! Login or Sign Up