The Expression Modifier is a bit of a different beast than a simple expression field. The modifier's 'out' expressions can only receive input from its own fields—the Number In and Point In controls on the Controls tab. You can rename them on the Config tab, but you still have to use their original shortcut names in the expression itself: n1, n2, p1x, p2y, etc.
Let's suppose you put your myTime variable in Number In 1, and myFreq in Number In 2. In the Number Out field, you could use this expression:
noise2(n1, n1)*n2
The Modifier limits you to having only 27 such variables (9 scalars and 9 2d vectors). The Out fields are essentially just one big return statement—whatever is in there has to be a single formula, not a script.
Simple expressions using the colon prefix give you access to most of the Lua scripting language instead of the subset available in the modifier, and you can create User Controls to hold your variables if you need something interactive. Here's an example of a Dissolve node that uses that technique to randomly switch between its inputs:
- Code: Select all
{
Tools = ordered() {
RandomSwitch_2 = Dissolve {
Transitions = {
[0] = "DFTDissolve"
},
CtrlWZoom = false,
NameSet = true,
Inputs = {
Mix = Input {
Value = 0,
Expression = ":t0=0; randomseed(RandomSeed); while t0<=time do off=random(MinimumOffTime,MaximumOffTime); on=random(MinimumOnTime,MaximumOnTime); t=time-t0; t0=t0+on+off; end; n=t0-on; if t>off then return 1; else return 0; end",
},
Comments = Input { Value = "Randomly switches the Mix control between 0 and 1. Adjust the frequency of switching using the Max and Min sliders. \r\n\r\nMuse Effects Elements Library, Glitch Tools Collection\r\nby Bryan Ray.\r\nwww.musevfx.com", },
MinimumOffTime = Input { Expression = "controlPanel_timeStutter.MinOffTime", },
MaximumOffTime = Input { Expression = "controlPanel_timeStutter.MaxOffTime", },
MinimumOnTime = Input { Expression = "controlPanel_timeStutter.MinShuffleDuration", },
MaximumOnTime = Input { Expression = "controlPanel_timeStutter.MaxShuffleDuration", },
RandomSeed = Input {
Value = 67,
Expression = "controlPanel_timeStutter.RandomSeed+250",
},
},
ViewInfo = OperatorInfo { Pos = { 674, 31 } },
UserControls = ordered() {
MinimumOffTime = {
INP_MaxAllowed = 10000,
INP_Integer = true,
INPID_InputControl = "SliderControl",
IC_ControlPage = 0,
INP_MaxScale = 30,
INP_Default = 3,
INP_MinAllowed = 0,
LINKID_DataType = "Number",
LINKS_Name = "Minimum Off Time",
},
MaximumOffTime = {
INP_MaxAllowed = 10000,
INP_Integer = true,
INPID_InputControl = "SliderControl",
IC_ControlPage = 0,
INP_MaxScale = 60,
INP_Default = 10,
INP_MinScale = 1,
INP_MinAllowed = 0,
LINKID_DataType = "Number",
LINKS_Name = "Maximum Off Time",
},
MinimumOnTime = {
INP_MaxAllowed = 10000,
INP_Integer = true,
INPID_InputControl = "SliderControl",
IC_ControlPage = 0,
INP_MaxScale = 30,
INP_Default = 3,
INP_MinAllowed = 0,
LINKID_DataType = "Number",
LINKS_Name = "Minimum On Time",
},
MaximumOnTime = {
INP_MaxAllowed = 10000,
INP_Integer = true,
INPID_InputControl = "SliderControl",
IC_ControlPage = 0,
INP_MaxScale = 60,
INP_Default = 10,
INP_MinScale = 1,
INP_MinAllowed = 0,
LINKID_DataType = "Number",
LINKS_Name = "Maximum On Time",
},
RandomSeed = {
LINKID_DataType = "Number",
INP_Default = 0,
IC_ControlPage = 0,
INPID_InputControl = "SliderControl",
LINKS_Name = "Random Seed",
}
}
}
},
ActiveTool = "RandomSwitch_2"
}
If you expand the expression into discrete lines, it may look familiar. I cribbed the algorithm from Motionscript.com, and I've seen similar timeline segmentation expressions in AE frequently.
- Code: Select all
:t0=0; randomseed(RandomSeed);
while t0<=time do
off=random(MinimumOffTime,MaximumOffTime);
on=random(MinimumOnTime,MaximumOnTime);
t=time-t0;
t0=t0+on+off;
end;
n=t0-on;
if t>off then
return 1;
else
return 0;
end