Page 1 of 1

Expression for Count up to a certain number

PostPosted: Tue Dec 28, 2021 4:27 pm
by ToteMusik
Hello,

I'm trying to solve one task, but can't find a solution.
I have a counter, that counts to a specific number, and it works pretty well, as long as I use it in this way.

Code: Select all
Text(floor(time^2*22500/comp.RenderEnd^2))


The issue is, that I have a fusion clip that's longer than I want the animation to run, and comp.RenderEnd plays the animation until the end of the fusion clip.

Found this post, but it does not work for me.
Expression for count up with a set stop number

I need to adjust the starting and ending-point/timeframe.

For example: Start at TF 102 from 0 and count to 22500 until TF 289 and stay there.

Thanks for your advice.

Re: Expression for Count up to a certain number

PostPosted: Tue Dec 28, 2021 4:46 pm
by Sander de Regt
I don't know how to write this in code, but I think you'll want to use some sort of if (or iif) statement, that basically says: if the number is lower than (the desired end number) show that number, else show the desired end number. I don't think it will be difficult to weite out, but my expression skills are failing me atm.

Re: Expression for Count up to a certain number

PostPosted: Tue Dec 28, 2021 4:52 pm
by ToteMusik
Yes, I don't know either. ;)

Yes, I don't know either. ;)

That's why I ask. I'm not a hero when it comes to coding.

In the post I mentioned, there was this snipped.

Code: Select all
iif(time>=88, 88, time)


But I don't know how to rewrite it, to fit my requirements.

Re: Expression for Count up to a certain number

PostPosted: Tue Dec 28, 2021 5:02 pm
by Frank Feijen
Wouldn't it be simpler to omit comp.Renderend in this case?

Re: Expression for Count up to a certain number

PostPosted: Tue Dec 28, 2021 6:58 pm
by xunile
This isn't necessarily the best way, but I did it with 2 nodes, a Custom Tool node and a Text+ node. I added the Custom Tool node then set the NumberIn1 to the first part of the range, in your example 102. I then set the NumberIn2 to 289. I then right-clicked on the NumberIn3 and clicked on Expression. I then entered the following expression.

Code: Select all
iif(time < 102 , 0 , floor(((c1.NumberIn1 + (time - c1.NumberIn1) )/ c1.NumberIn2) * 22500) )


I then switched to the Text+ node and chose expression for the text entry box. I entered the following expression.

Code: Select all
iif( c1.NumberIn3 > 22500 , 22500 , c1.NumberIn3)


This allowed me to enter any two numbers for NumberIn1 and NumberIn2 and it will count from 0 to 22500 and stop after it gets to the second number.


Here are the two nodes if you just want to copy and paste them into your Node Editor.

Code: Select all
{
   Tools = ordered() {
      Text2 = TextPlus {
         CtrlWZoom = false,
         Inputs = {
            GlobalOut = Input { Value = 397, },
            Width = Input { Value = 1920, },
            Height = Input { Value = 1080, },
            UseFrameFormatSettings = Input { Value = 1, },
            ["Gamut.SLogVersion"] = Input { Value = FuID { "SLog2" }, },
            StyledText = Input {
               Value = "22500",
               Expression = "iif( c1.NumberIn3 > 22500 , 22500 , c1.NumberIn3)",
            },
            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 = { 213.333, -61.1213 } },
      },
      c1 = Custom {
         NameSet = true,
         Inputs = {
            NumberIn1 = Input { Value = 102, },
            NumberIn2 = Input { Value = 289, },
            NumberIn3 = Input { Expression = "iif(time < 102 , 0 , floor(((c1.NumberIn1 + (time - c1.NumberIn1) )/ c1.NumberIn2) * 22500) ) ", },
            LUTIn1 = Input {
               SourceOp = "c1LUTIn1",
               Source = "Value",
            },
            LUTIn2 = Input {
               SourceOp = "c1LUTIn2",
               Source = "Value",
            },
            LUTIn3 = Input {
               SourceOp = "c1LUTIn3",
               Source = "Value",
            },
            LUTIn4 = Input {
               SourceOp = "c1LUTIn4",
               Source = "Value",
            },
            NumberControls = Input { Value = 1, },
         },
         ViewInfo = OperatorInfo { Pos = { 615.333, -54.4546 } },
      },
      c1LUTIn1 = 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,
      },
      c1LUTIn2 = 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,
      },
      c1LUTIn3 = 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,
      },
      c1LUTIn4 = 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,
      }
   }
}

Re: Expression for Count up to a certain number

PostPosted: Wed Dec 29, 2021 9:54 am
by ToteMusik
Hi Eric,

thank you very much, for your great example!
Posted an answer before, but the forum did not post it.

It's works quite well, with one little exception.

I can set 0, but when I start at TF 102 for example, the count up will not start at 0. It starts at ~7900. I guess it's because it's counting the TFs before and jumps to that number.

That's a little issue, but I can life with that.

Great work! Thanks again.

Re: Expression for Count up to a certain number

PostPosted: Wed Dec 29, 2021 5:02 pm
by xunile
You're welcome, glad I could help. It starts at 0 but then does jump to a high number because the range of frames it is working with is pretty low. It uses the ratio between the start and end frame to create the count. If you use the following code in the custom tool it will start lower at around 900. You can tweak it to lower it more but since it is a simulated count it should look ok at 30 fps.

Code: Select all
iif(time < 102 , 0 , floor((time ^  3) * 22500 / c1.NumberIn2 ^ 3))

Re: Expression for Count up to a certain number

PostPosted: Wed Dec 29, 2021 5:37 pm
by ToteMusik
Thank you again, and this will work great for me, and my animation works, like I want it to do! :D
I'll just expand the range, that's ok.