diff options
author | sanine <sanine.not@pm.me> | 2022-01-26 02:32:06 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-01-26 02:32:06 -0600 |
commit | 6b687b91e788b4e91a6ed30640a2477b9596b954 (patch) | |
tree | be0ebf99cd8ff3776f59a33b42ef22ab07c71a6c /experimental/tectonics/drawing.c | |
parent | 672819693ddf1d203c304697b63f44059cff09b6 (diff) |
refactor: move drawing functions into drawing.h/drawing.c
Diffstat (limited to 'experimental/tectonics/drawing.c')
-rw-r--r-- | experimental/tectonics/drawing.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/experimental/tectonics/drawing.c b/experimental/tectonics/drawing.c new file mode 100644 index 0000000..91f873b --- /dev/null +++ b/experimental/tectonics/drawing.c @@ -0,0 +1,56 @@ +#include <stddef.h> +#include <math.h> + +#include "tectonics.h" +#include "geometry.h" +#include "drawing.h" + +void get_cairo_size(cairo_t *cr, int *width, int *height) +{ + cairo_surface_t *surface = cairo_get_target(cr); + *width = cairo_image_surface_get_width(surface); + *height = cairo_image_surface_get_height(surface); +} + + +void draw_world(cairo_t *cr, struct world_t *world) +{ + int width, height; + get_cairo_size(cr, &width, &height); + double r = ((double)width) / (100*sqrt(world->n_points)); + cairo_set_source_rgba(cr, 1, 0, 0, 1); + + for (int i=0; i<world->n_points; i++) { + struct point_t *pt = world->points + i; + double xc = pt->x * width; + double yc = pt->y * height; + cairo_arc(cr, xc, yc, r, 0, 2*M_PI); + cairo_stroke(cr); + } + + //draw_quadtree(cr, &(world->tree)); +} + + +void draw_quadtree(cairo_t *cr, struct quadtree_node_t *node) +{ + int width, height; + get_cairo_size(cr, &width, &height); + + cairo_set_source_rgba(cr, 0, 0, 1, 1); + struct point_t center = node->region.center; + double half_dim = node->region.half_dim; + + double x = (center.x - half_dim) * width; + double y = (center.y - half_dim) * height; + + cairo_rectangle(cr, x, y, 2*half_dim * width, 2*half_dim * height); + cairo_stroke(cr); + + if (node->nw != NULL) { + draw_quadtree(cr, node->nw); + draw_quadtree(cr, node->ne); + draw_quadtree(cr, node->sw); + draw_quadtree(cr, node->se); + } +} |