main moved to top and comments added for functions

This commit is contained in:
Ole Morud
2022-06-07 15:40:34 +02:00
parent d48a3b8de1
commit 86fcacd841

View File

@@ -1,5 +1,5 @@
#include <unistd.h>
#include "graphics.h"
#include <stdlib.h>
#include <string.h>
@@ -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;
}