# Infinity Loop between two values

## Recommended Posts

Posted (edited)

I need to make a code like this:

Initial value 11

Final value 33

I want to insert the code on the property time (that changes) of the program I use

So I want the code to interpolate through the time between numbers 11 and 33, meaning this code will move 22 seconds in time

I want that when the code results in the final value, that is, arrive at the value 33
It is reinitiated, thus causing an infinite loop. Going from 11 to 33 in 22 seconds and then repeating on and on.

There is a codebase that may allow time to be used in a dynamic way:

linear (t, tMin, tMax, value1, value2)

There it is (time, start time, end time, initial value, final value)

Maybe this code is useful ... I do not know. It is an interpolation code

Edited by tiscavalcanti

##### Share on other sites

Have you built this function or are you asking how to build it?

In Javascript, you would have to implement it by repeatedly calling a function using setTimeout, setInterval or requestAnimationFrame.

• 1

##### Share on other sites

4 minutes ago, Ingolme said:

Have you built this function or are you asking how to build it?﻿

In Javascript, you would have to implement it by repeatedly calling a function using setTimeout, setInterval or requestAnimationFrame.﻿

##### Share on other sites

You need to learn two things:

1. Linear interpolation
2. Timing in Javascript

Linear interpolation is described here with some examples of function implementations: https://en.wikipedia.org/wiki/Linear_interpolation#Programming_language_support

The time t in linear interpolation is a value from 0 to 1. To get this value, you just divide the amount of time that has passed since the animation started by the total duration of the animation. In pseudo-code, something like this:

t = (currentTime - startTime) / (endTime - startTime)

When the animation starts, you need to store the current time in a variable startTime to use it in the formula described above.

In Javascript, when using setTimeout or setInterval, you get the startTime and currentTime values from the Date object's getTime() method. If you're using requestAnimationFrame, see Mozilla's documentation, the current time is given as a parameter in the callback function. When using requestAnimationFrame you can get the startTime value using performance.now() right before the animation begins.

• 1

##### Share on other sites
7 hours ago, Ingolme said:

You need to learn two things:

1. Linear interpolation
2. Timing in Javascript

Linear interpolation is described here with some examples of function implementations: https://en.wikipedia.org/wiki/Linear_interpolation#Programming_language_support

The time t in linear interpolation is a value from 0 to 1. To get this value, you just divide the amount of time that has passed since the animation started by the total duration of the animation. In pseudo-code, something like this:

t = (currentTime - startTime) / (endTime - startTime)

When the animation starts, you need to store the current time in a variable startTime to use it in the formula described above.

In Javascript, when using setTimeout or setInterval, you get the startTime and currentTime values from the Date object's getTime() method. If you're using requestAnimationFrame, see Mozilla's documentation, the current time is given as a parameter in the callback function. When using requestAnimationFrame you can get the startTime value using performance.now() right before the animation begins.

Your information is quite useful, I will delve into the links, and in fact, I use video program that uses expressions based on JS ...

Look, I just figured out a way to sort this out ... maybe it'll work ...

Do you know how I can make a variable go from 0 to 22, and when it reaches 22, return to 0?

Type a slide inside the number 22, that is, from 0 to 22, it results in 22, and from 22 to 44 it also results in 22, as if the variable was reset every time it was 22, then 23 would be 1 , and 45, 1 also, and so on.

##### Share on other sites

footage = comp("Footage").layer(1);

IP = footage.inPoint;
OP = footage.outPoint;

IP+time%(OP-IP);

I got it!

## Create an account

Register a new account