diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/display.c | 8 | ||||
| -rw-r--r-- | src/main.c | 35 | 
2 files changed, 23 insertions, 20 deletions
| diff --git a/src/display.c b/src/display.c index a1ee9f7..2a46493 100644 --- a/src/display.c +++ b/src/display.c @@ -29,10 +29,14 @@ void dspl_destroy()  void dspl_draw_circle(int cx, int cy, int r)  { -    DrawCircle((info.width/2) + cx, (info.height/2) + cy, r, RED); +    int offsetx = (info.width/2); +    int offsety = (info.height/4); +    DrawCircle(offsetx + cx, offsety + cy, r, RED);  }  void dspl_draw_line(int x1, int y1, int x2, int y2, int c)  { -    DrawLine((info.width/2) + x1, (info.height/2) + y1, (info.width/2) + x2, (info.height/2) + y2 , (c == 0) ? BLUE : RED); +    int offsetx = (info.width/2); +    int offsety = (info.height/4); +    DrawLine(offsetx + x1, offsety + y1, offsetx + x2, offsety + y2 , (c == 0) ? BLUE : RED);  } @@ -1,34 +1,37 @@  #include <stdio.h> -#include <time.h>  #include <math.h>  #include "display.h"  #define W 1600  #define H 900 -#define FPS 460 +#define FPS 1000 +#define SCALE 1000 +#define SWING_SCALE 15 +  #define RFPS 1/FPS  #define PI 3.141592654  const float s = (PI/180 * 25); // rad -const int l = 500; // mm -const int m = 1;  // kg -const float g = -9810.0f; // mm/s^2 +const float l = 0.5 * SCALE; // m +const int m = 7;  // kg +const float g = -9.81f * SCALE; // m/s^2  float t;  float v;  float a;  float secs = 0.0f; -int cycles = 20; +int swings = 2 * SWING_SCALE;  int has_reached_starting_amp(float old_t)  { -    if(cycles % 2 == 0 && t < 0) { +    if(swings % 2 == 0 && t < 0) {          if(old_t < t) return 1; -    } else if(cycles % 2 == 1 && t > 0) { +    } else if(swings % 2 == 1 && t > 0) {          if(old_t > t) return 1;      } return 0;  } +  void update()  {      float old_t = t; @@ -37,25 +40,21 @@ void update()      t += v * RFPS;      if(has_reached_starting_amp(old_t)) { -        puts("new cycle"); -        cycles += 1; +        puts("new swing"); +        swings += 1;      } -    if(cycles == 20) { -        printf("sec: %f\n", secs); +    if(swings >= 2 * SWING_SCALE) { +        printf("period: %f\n", secs/SWING_SCALE);          secs = 0.0f; -        cycles = 0; +        swings = 0;      }      secs += (float)RFPS; - -      float px = sinf(t) * l;      float py = cosf(t) * l;      dspl_draw_line(px, py, 0, 0, 0); -    dspl_draw_circle(px, py, m*5); - - +    dspl_draw_circle(px, py, m);  }  int main(void) | 
