aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2022-10-28 22:23:02 +0300
committerkartofen <mladenovnasko0@gmail.com>2022-10-28 22:23:02 +0300
commit7363f062baf99097a9a5e2e4366cced0afd526cb (patch)
treec1578d5fdbf9639aada5d48c6aa8e48565c43816 /src/main.c
parent8e235c8e6641f223c59e8502ac0caebf9c5c1ffc (diff)
wasm supportHEADmaster
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c55
1 files changed, 41 insertions, 14 deletions
diff --git a/src/main.c b/src/main.c
index 4742ab8..dd37021 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,27 +1,36 @@
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
#include <math.h>
#include "display.h"
-#define W 1600
-#define H 900
-#define FPS 1000
-#define SCALE 1000
-#define SWING_SCALE 15
+#define W 800
+#define H 600
+
+#ifndef PLATFORM_WEB
+ #define FPS 120
+#else
+ #define FPS 60
+#endif
+
+#define SCALE 800
+#define CYCLES 5
#define RFPS 1/FPS
#define PI 3.141592654
+#define g -9.81f * SCALE
-const float s = (PI/180 * 25); // rad
-const float l = 0.5 * SCALE; // m
-const int m = 7; // kg
-const float g = -9.81f * SCALE; // m/s^2
+float s = 25; // starting agnle
+float l = 0.5; // lenght
+float m = 0.01; // mass in kg
float t;
float v;
float a;
float secs = 0.0f;
-int swings = 2 * SWING_SCALE;
+int swings = 2 * CYCLES;
int has_reached_starting_amp(float old_t)
{
@@ -34,17 +43,22 @@ int has_reached_starting_amp(float old_t)
void update()
{
+ if(secs == 0.0f) {
+ printf("\nStarting angle: %f", s/(PI/180));
+ printf("\nLenght: %f", l/SCALE);
+ printf("\nMass: %f\n", m/SCALE);
+ }
+
float old_t = t;
a = (g/l) * sinf(t);
v += a * RFPS;
t += v * RFPS;
if(has_reached_starting_amp(old_t)) {
- puts("new swing");
swings += 1;
}
- if(swings >= 2 * SWING_SCALE) {
- printf("period: %f\n", secs/SWING_SCALE);
+ if(swings >= 2 * CYCLES) {
+ printf("period: %f\n", secs/CYCLES);
secs = 0.0f;
swings = 0;
}
@@ -57,8 +71,21 @@ void update()
dspl_draw_circle(px, py, m);
}
-int main(void)
+int main(int argc, char **argv)
{
+ if(argc != 1 && argc != 4) {
+ puts("Please provide either 0 or 3 arguments:\n\t1st is starting angle in degrees\n\t2nd is lenght in meters\n\t3rd is mass in kilograms");
+ return 1;
+ }
+
+ float arg_s = strtof(argv[1], NULL);
+ float arg_l = strtof(argv[2], NULL);
+ float arg_m = strtof(argv[3], NULL);
+
+ s = ((arg_s == 0.0f) ? s : arg_s) * PI/180;
+ l = ((arg_l == 0.0f) ? l : arg_l) * SCALE;
+ m = ((arg_m == 0.0f) ? m : arg_m) * SCALE;
+
t = s;
v = 0;
a = 0;