From 86fcacd84145041bdd420a3651873a8d5e59fd90 Mon Sep 17 00:00:00 2001 From: Ole Morud Date: Tue, 7 Jun 2022 15:40:34 +0200 Subject: [PATCH] main moved to top and comments added for functions --- physics.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/physics.c b/physics.c index 5336df2..bc2eff3 100644 --- a/physics.c +++ b/physics.c @@ -1,5 +1,5 @@ - +#include #include "graphics.h" #include #include @@ -23,21 +23,14 @@ typedef struct Link { } Link; - -void draw_link(Canvas* c, Link* l){ - line(c, l->a->x, l->a->y, l->b->x, l->b->y); -} - -void update_point(Point* p){ - uint tempx = p->x; - uint tempy = p->y; - p->x += (p->x - p->px) + p->fx; - p->y += (p->y - p->py) + p->fy; - p->px = tempx; - p->py = tempy; -} +void draw_link(Canvas* c, Link* l); +void update_point(Point* p); + +/* + * main + */ int main(){ char *data = malloc(40*40); Canvas c = {40, 40, data}; @@ -64,9 +57,26 @@ int main(){ usleep(1000000/FRAMERATE); } - - return 0; } +/* + * Draws a line between linked points + */ +void draw_link(Canvas* c, Link* l){ + line(c, l->a->x, l->a->y, l->b->x, l->b->y); +} + +/* + * Updates the position of a point + * the update is based on its position, its position in the previous frame (px, py) and the forces acting upon it (fx,fy) + */ +void update_point(Point* p){ + uint tempx = p->x; + uint tempy = p->y; + p->x += (p->x - p->px) + p->fx; + p->y += (p->y - p->py) + p->fy; + p->px = tempx; + p->py = tempy; +}