Merge pull request #270 from vicenteferrari/lerp

[added] lerp, with both an unprecise and a precise option.
This commit is contained in:
Ashwek Swamy 2019-11-02 22:26:13 +05:30 committed by GitHub
commit e07f67b56d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

28
misc/lerp.c Normal file
View File

@ -0,0 +1,28 @@
#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;
}