Blackmagic Fusion Simple Expressions-Cookbook + Tutorial

Math Operations

Here are a few examples of using some arbitrary math operations. I demonstrate some of these using a Custom tools Point Positions, but you can use all other controls as well. I also won’t cover many of these, for more you can look here as these are mostly the normal Lua functions.

Get Maximum or Minimum of different values

If you need the maximum value of a set of numbers you can use the max(value1, value2, ...) Expression. It’s very simple to use and does exactly as you expect. In my example, I have used three controls but you can use more or less.

Here it prints the maximum X value of the three Position Controls of the Custom Tool:

Fusion math.max operation
:return math.max(CT.PointIn1.X,CT.PointIn2.X,CT.PointIn3.X)

You can do the opposite by exchanging the max() with min().

Convert to an integer with math.floor, math.ceil

Works exactly like you might know from Lua. This will return a full integer of a floating value. For example, 1.6 returns 1.

math.floor(value)
math.floor
math.ceil(value)

This will do the same except you get the next integer, so 1.6 would return 2.

Random numbers with math.random

As the name suggest, this will return random numbers, you can set a min and max number.

math.random()

will return a random value between 0 and 1.

math.random(value1)

will return a random number between 1 and value1.

math.random(value1, value2)

will return a random number between value1 and value2.

Quick notice! While I have added these for the sake of it, you won’t actually need these. Most users, especially After Effects users, only want a wiggle() equivalent, math.random is not it. It’s much easier and better to use the Shake Modifier and the control you want to move/wiggle/rotate.

{ Tools = ordered() { CT = Custom { NameSet = true, Inputs = { PointIn1 = Input { Value = { 1, 0.693362193362193 }, }, PointIn2 = Input { Value = { 0.37339997964998, 0.321067821067821 }, }, PointIn3 = Input { Value = { 0.784622784622785, 0.497113997113997 }, }, NumberIn1 = Input { Value = 10, }, LUTIn1 = Input { SourceOp = “CTLUTIn1”, Source = “Value”, }, LUTIn2 = Input { SourceOp = “CTLUTIn2”, Source = “Value”, }, LUTIn3 = Input { SourceOp = “CTLUTIn3”, Source = “Value”, }, LUTIn4 = Input { SourceOp = “CTLUTIn4”, Source = “Value”, }, Intermediate1 = Input { Value = “dist(PointIn1.X,PointIn1.Y,PointIn2.X,PointIn2.Y)”, }, RedExpression = Input { Value = “dist(p1x,p1y,p2x,p2y)\n”, }, }, ViewInfo = OperatorInfo { Pos = { 440, 16.5 } }, }, CTLUTIn1 = LUTBezier { KeyColorSplines = { [0] = { [0] = { 0, RH = { 0.333333333333333, 0.333333333333333 }, Flags = { Linear = true } }, [1] = { 1, LH = { 0.666666666666667, 0.666666666666667 }, Flags = { Linear = true } } } }, SplineColor = { Red = 204, Green = 0, Blue = 0 }, NameSet = true, }, CTLUTIn2 = LUTBezier { KeyColorSplines = { [0] = { [0] = { 0, RH = { 0.333333333333333, 0.333333333333333 }, Flags = { Linear = true } }, [1] = { 1, LH = { 0.666666666666667, 0.666666666666667 }, Flags = { Linear = true } } } }, SplineColor = { Red = 0, Green = 204, Blue = 0 }, NameSet = true, }, CTLUTIn3 = LUTBezier { KeyColorSplines = { [0] = { [0] = { 0, RH = { 0.333333333333333, 0.333333333333333 }, Flags = { Linear = true } }, [1] = { 1, LH = { 0.666666666666667, 0.666666666666667 }, Flags = { Linear = true } } } }, SplineColor = { Red = 0, Green = 0, Blue = 204 }, NameSet = true, }, CTLUTIn4 = LUTBezier { KeyColorSplines = { [0] = { [0] = { 0, RH = { 0.333333333333333, 0.333333333333333 }, Flags = { Linear = true } }, [1] = { 1, LH = { 0.666666666666667, 0.666666666666667 }, Flags = { Linear = true } } } }, SplineColor = { Red = 204, Green = 204, Blue = 204 }, NameSet = true, }, mathmax = TextPlus { NameSet = true, Inputs = { GlobalIn = Input { Value = 1, }, Width = Input { Value = 1920, }, Height = Input { Value = 1080, }, [“Gamut.SLogVersion”] = Input { Value = FuID { “SLog2” }, }, StyledText = Input { Value = “0.83020683020683”, Expression = “:return math.max(CT.PointIn1.X,CT.PointIn2.X,CT.PointIn3.X)”, }, Font = Input { Value = “Open Sans”, }, Style = Input { Value = “Bold”, }, VerticalJustificationNew = Input { Value = 3, }, HorizontalJustificationNew = Input { Value = 3, }, ManualFontKerningPlacement = Input { Value = StyledText { Array = { }, Value = “” }, }, }, ViewInfo = OperatorInfo { Pos = { 440, 82.5 } }, }, mathfloor = TextPlus { NameSet = true, Inputs = { GlobalIn = Input { Value = 1, }, Width = Input { Value = 1920, }, Height = Input { Value = 1080, }, [“Gamut.SLogVersion”] = Input { Value = FuID { “SLog2” }, }, CharacterSpacing = Input { Value = 1.638, }, StyledText = Input { Value = “1”, Expression = “:return math.floor(CharacterSpacingClone)”, }, Font = Input { Value = “Open Sans”, }, Style = Input { Value = “Bold”, }, VerticalJustificationNew = Input { Value = 3, }, HorizontalJustificationNew = Input { Value = 3, }, ManualFontKerningPlacement = Input { Value = StyledText { Array = { }, Value = “” }, }, }, ViewInfo = OperatorInfo { Pos = { 605, 82.5 } }, }, mathrandom = TextPlus { CtrlWZoom = false, NameSet = true, Inputs = { GlobalIn = Input { Value = 1, }, Width = Input { Value = 1920, }, Height = Input { Value = 1080, }, [“Gamut.SLogVersion”] = Input { Value = FuID { “SLog2” }, }, StyledText = Input { Value = “0.079784390874788”, Expression = “:return math.random()”, }, Font = Input { Value = “Open Sans”, }, Style = Input { Value = “Regular”, }, VerticalJustificationNew = Input { Value = 3, }, HorizontalJustificationNew = Input { Value = 3, }, ManualFontKerningPlacement = Input { Value = StyledText { Array = { }, Value = “” }, }, }, ViewInfo = OperatorInfo { Pos = { 770, 82.5 } }, }, mathceil = TextPlus { NameSet = true, Inputs = { GlobalIn = Input { Value = 1, }, Width = Input { Value = 1920, }, Height = Input { Value = 1080, }, [“Gamut.SLogVersion”] = Input { Value = FuID { “SLog2” }, }, CharacterSpacing = Input { Value = 0.252, }, StyledText = Input { Value = “1”, Expression = “:return math.ceil(CharacterSpacingClone)”, }, Font = Input { Value = “Open Sans”, }, Style = Input { Value = “Bold”, }, VerticalJustificationNew = Input { Value = 3, }, HorizontalJustificationNew = Input { Value = 3, }, ManualFontKerningPlacement = Input { Value = StyledText { Array = { }, Value = “” }, }, }, ViewInfo = OperatorInfo { Pos = { 605, 181.5 } }, }, mathmin = TextPlus { NameSet = true, Inputs = { GlobalIn = Input { Value = 1, }, Width = Input { Value = 1920, }, Height = Input { Value = 1080, }, [“Gamut.SLogVersion”] = Input { Value = FuID { “SLog2” }, }, StyledText = Input { Value = “0.393342999593”, Expression = “:return math.min(CT.PointIn1.X,CT.PointIn2.X,CT.PointIn3.X)”, }, Font = Input { Value = “Open Sans”, }, Style = Input { Value = “Bold”, }, VerticalJustificationNew = Input { Value = 3, }, HorizontalJustificationNew = Input { Value = 3, }, ManualFontKerningPlacement = Input { Value = StyledText { Array = { }, Value = “” }, }, }, ViewInfo = OperatorInfo { Pos = { 440, 181.5 } }, } } }

On the next page we will look at Metadata.

Quickly share this!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Scroll to top
0
Would love your thoughts, please comment.x