Need help with an Expression please.

Get answers to your questions about color grading, editing and finishing with DaVinci Resolve.
  • Author
  • Message
Offline

_noirs_

  • Posts: 6
  • Joined: Fri Nov 08, 2024 9:11 pm
  • Real Name: hans fick

Need help with an Expression please.

PostFri May 02, 2025 11:32 pm

I want to insert an Expression to make this go from 0 to 1 within 1 second, and once it reaches 1 go back from 1 to 0 within another second. I would greatly appreciate your help! Thanks in advance.
Image here:

https://imgur.com/ClC3D7c
Offline

Christoph Schmid

  • Posts: 814
  • Joined: Thu Sep 26, 2019 10:15 am
  • Real Name: Christoph Schmid

Re: Need help with an Expression please.

PostSat May 03, 2025 12:59 pm

Sinus Curve (half period)
Code: Select all
: start = 0;
fps = comp:GetPrefs("Comp.FrameFormat.Rate");
if time > start and time <= (start+fps*2) then return sin((time-start)/fps*(pi/2));
else return 0;end


Linear
Code: Select all
: start = 0;
fps = comp:GetPrefs("Comp.FrameFormat.Rate");
if time > start and time <= (start+fps) then return (time-start)/fps;
elseif time > (start + fps) and time <= (start+fps*2) then return 2-(time-start)/fps;
else return 0;end


Cosinus (smooth | complete period)
Code: Select all
: start = 0;
fps = comp:GetPrefs("Comp.FrameFormat.Rate");
if time > start and time <= (start+fps*2) then return cos((time-start)/fps*pi+pi)/2+0.5;
else return 0;end


Change the start value to the frame you want to start the animation.
Do not use “Select all” to copy the code as this will add an indent.

Davinci Resolve Studio 20.0B3 Build 38
Windows 10 Pro 22H2
Davinci Resolve Studio 19.1.4 Build 11
Linux Ubuntu Studio 24.04 (Rocky 8.6 Container)
Offline

Sander de Regt

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

Re: Need help with an Expression please.

PostSat May 03, 2025 2:26 pm

If you don't use an expression, but looped keyframes for this, there's a chance that caching will work a little better.
Sander de Regt

ShadowMaker SdR
The Netherlands
Offline
User avatar

KrunoSmithy

  • Posts: 4460
  • Joined: Fri Oct 20, 2023 11:01 pm
  • Warnings: 1
  • Real Name: Kruno Stifter

Re: Need help with an Expression please.

PostSat May 03, 2025 3:16 pm

+1 for loop keyframes.
Offline

Christoph Schmid

  • Posts: 814
  • Joined: Thu Sep 26, 2019 10:15 am
  • Real Name: Christoph Schmid

Re: Need help with an Expression please.

PostSat May 03, 2025 4:40 pm

The OP didn't write that he wanted to do a loop.
But if I think about it, it doesn't really make much sense to use an expression for a simple up and down...
And if you're saying it's faster to use loop keyframes, the OP should do that.
If for some reason the expression is still needed:

Code: Select all
:start = 0;
fps = comp:GetPrefs("Comp.FrameFormat.Rate");
duration = fps * 2;
loopTime = (time - start) % duration;
if time >= start then return (cos(loopTime / duration * 2 * pi - pi) + 1) / 2;
else return 0; end

Davinci Resolve Studio 20.0B3 Build 38
Windows 10 Pro 22H2
Davinci Resolve Studio 19.1.4 Build 11
Linux Ubuntu Studio 24.04 (Rocky 8.6 Container)
Offline

_noirs_

  • Posts: 6
  • Joined: Fri Nov 08, 2024 9:11 pm
  • Real Name: hans fick

Re: Need help with an Expression please.

PostMon May 05, 2025 8:28 pm

Christoph, thanks so much for your elaborate reply, super appreciate it!

Return to DaVinci Resolve

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 269 guests