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.

Revisions

  1. @r-lyeh r-lyeh revised this gist Apr 5, 2016. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions walkrate.c
    Original file line number Diff line number Diff line change
    @@ -8,11 +8,11 @@ int main( int argc, const char **argv ) {

    float excess = fmodf( distance, cycle );

    // P% playrate -> distance
    // ?% playrate -> distance - excess
    // P% playrate -> cycle + excess
    // ?% playrate -> cycle

    // ?% playrate = P% * ( distance - excess ) / (distance)
    float playrate = 1.00f * (distance - excess) / distance;
    // ?% 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;

  2. @r-lyeh r-lyeh renamed this gist Apr 5, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @r-lyeh r-lyeh created this gist Apr 5, 2016.
    21 changes: 21 additions & 0 deletions walkrate
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #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 -> distance
    // ?% playrate -> distance - excess

    // ?% playrate = P% * ( distance - excess ) / (distance)
    float playrate = 1.00f * (distance - excess) / distance;
    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);
    }
    }