Skip to content

Instantly share code, notes, and snippets.

@r-lyeh-archived
Last active April 5, 2016 17:00
Show Gist options
  • Save r-lyeh-archived/1c9f04cf6d8ff0a7b4889e64d81d5d40 to your computer and use it in GitHub Desktop.
Save r-lyeh-archived/1c9f04cf6d8ff0a7b4889e64d81d5d40 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main( int argc, const char **argv ) {
if( argc >= 3 ) {
float cycle = atof(argv[1]);
float distance = atof(argv[2]);
float excess = fmodf( distance, cycle );
// P% playrate -> cycle + excess
// ?% playrate -> cycle
// ?% playrate = P% * (cycle) / (cycle+excess)
float playrate = 1.00f * (cycle) / (cycle+excess);
playrate = playrate > 0 ? 1.f / playrate : 0;
playrate = playrate > 1.5 ? playrate - 1 : playrate;
printf("walk-cycle=%f estimated-distance=%f estimated-excess=%f play-rate=%f\n", cycle, distance, excess, playrate);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment