lerp Algorithm

The Lerp (Linear Interpolation) algorithm is a mathematical technique commonly used in computer graphics, animation, and game development to smoothly transition between two values or points over a specified time interval. It is a simple and efficient way to calculate intermediate values in a range, given a starting value, an ending value, and a parameter representing the position between the two. Lerp is particularly useful for creating smooth animations, blending between colors, or smoothly moving characters and objects in a 3D space. The Lerp algorithm works by taking a starting value (A), an ending value (B), and a parameter (t) that represents the position between the two values, usually in the range of 0 to 1. When t is 0, the algorithm returns the starting value (A), and when t is 1, it returns the ending value (B). For any value of t between 0 and 1, the algorithm calculates the corresponding interpolated value by multiplying the difference between the ending and starting values (B - A) by the parameter t, and then adding the result to the starting value (A). This produces a new value that lies between A and B and represents a point along the linear path between the two. By gradually changing the value of t from 0 to 1, one can create a smooth transition between the starting and ending values.
#include <stdio.h>
#include <math.h>

float lerp(float k0, float k1, float t) {
    return k0 + t * (k1 - k0);
}

float lerp_precise(int k0, int k1, float t) {
    return (1 - t) * k0 + t * k1;
}

int main() {
    float start = 0;
	float finish = 5;
	float steps = 0;
    
	printf("Input a number, this is the bigger bound of the lerp:\n");
    scanf("%f", &finish);

    printf("Input a number, this is in how many steps you want to divide the lerp:\n");
    scanf("%f", &steps);

	for (int i = 0; i < steps + 1; i++) {
		printf("%f\n", lerp(start, finish, i / steps));
	}

    return 0;
}

LANGUAGE:

DARK MODE: