visualizations

Programmatic visualizations
git clone git://git.laack.co/visualizations.git
Log | Files | Refs | README

vert.c (677B)


      1 #include "vert.h"
      2 #include <math.h>
      3 #include <stdlib.h>
      4 #include <stdio.h>
      5 
      6 Vertex gen_vertex() {
      7     int y = rand() % 1440;
      8     int x = rand() % 5120;
      9     Vertex v;
     10     v.x = x;
     11     v.y = y;
     12     return v;
     13 }
     14 
     15 void print_vertex(Vertex* v) {
     16     printf("x: %i, y: %i", v->x, v->y);
     17 }
     18 
     19 Vertex* gen_vertices(int vtCount) {
     20     Vertex* vertices = (Vertex*)malloc(sizeof(Vertex) * vtCount);
     21     for(int i = 0; i < vtCount; ++i) {
     22         Vertex v = gen_vertex();
     23         vertices[i] = v;
     24     }
     25     return vertices;
     26 
     27 }
     28 
     29 float vert_dist(Vertex* v1, Vertex* v2) {
     30     float dx = (float)v1->x - (float)v2->x;
     31     float dy = (float)v1->y - (float)v2->y;
     32     return sqrt(dx*dx + dy*dy);
     33 }