Jump to: Board index » General » Fusion

Using an Expression to Create a Timer

Learn about 3D compositing, animation, broadcast design and VFX workflows.
  • Author
  • Message
Offline

mark_macrae_

  • Posts: 5
  • Joined: Tue Nov 13, 2018 5:33 am
  • Real Name: Mark MacRae

Using an Expression to Create a Timer

PostTue Nov 13, 2018 5:57 am

It took me several hours to figure this little thing out on my own, and I couldn't find anybody doing exactly this so I figured I should post my code in case it is useful to anybody else.

It's still not perfect, but it works pretty good.

What I wanted was a countdown from 10 secs to 0 (the start time), then have it start counting up. I suppose to could have done this using a couple of different timers, but I wanted it all in one expression.

As someone with a coding background, I knew it would be easy to write and if-then-else type code snipet. Reading up LUA language got me most of the way there, but there is a key piece of info that most tutorials on expressions in DaVinci do not mention. Namely, if you want to write more than one line of code in your express, you must begin with a colon (:), then end each line with a semi-colon (;).

Anyway, here's the code for my expression:
Code: Select all
:t = math.floor(time/29.97-10); if t < 0 then return Text(string.format("%02d",t)); elseif t == 0 then return Text("START"); else return Text(string.format("00:%02d",t)); end


It counts down from -10 to the word "START" at 0, then formats the seconds like a timer.

Here's a link to the video I used this element on:
(Sorry, this forum refuses to let me post the link no matter how I try, even though there is clearly a URL button here...)
You'll have to copy/paste the following after the / when you go to YouTube:
watch?v=mvxwoUMhAbM

The timer shows up soon after the intro.

In my example, my footage was 29.97 fps, you should substitute your own fps from you project settings. And the "-10" starts my timer at -10 secs instead of zero. Also, I didn't want the timer to run past about 53 seconds so I didn't bother actually coding it to display the minutes. You'll see the "00:" is just hard-coded.

I am posting this in the Fusion forum, but in fact I didn't use Fusion really, this is just a Text+ element in Resolve where I right-clicked the Styled Text and selected Expression.

Hopefully this helps somebody someday.
Offline

Sander de Regt

  • Posts: 3584
  • Joined: Thu Nov 13, 2014 10:09 pm

Re: Using an Expression to Create a Timer

PostTue Nov 13, 2018 9:15 pm

(Sorry, this forum refuses to let me post the link no matter how I try, even though there is clearly a URL button here...)

This is because this is your first post. When you become more of a regular, you will be able to post links like these



And you should definitely become more active. It's a nice use of code and an example for other people, because you show that with some effort you can make Fusion/Resolve do what you want it to. Nicely done and welcome.
Sander de Regt

ShadowMaker SdR
The Netherlands
Offline
User avatar

Igor Riđanović

  • Posts: 1596
  • Joined: Thu Jul 02, 2015 5:11 am
  • Location: Los Angeles, Calif.

Re: Using an Expression to Create a Timer

PostThu Nov 15, 2018 10:16 pm

I think you can do it with a one-liner. Something similar to this in a 23.976 timeline:

Code: Select all
10 + offset - floor(time/23.976)


... although, looking at your multi statement expression, you do have additional bells and whistles that require a more verbose solution. Well done!
www.metafide.com - DaVinci Resolve™ Apps

Return to Fusion

Who is online

Users browsing this forum: No registered users and 45 guests