diff options
-rw-r--r-- | experimental/tectonics/Makefile | 4 | ||||
-rw-r--r-- | experimental/tectonics/drawing.c | 56 | ||||
-rw-r--r-- | experimental/tectonics/drawing.h | 10 | ||||
-rw-r--r-- | experimental/tectonics/geometry.h | 3 | ||||
-rw-r--r-- | experimental/tectonics/output-relaxed.png | bin | 31195 -> 0 bytes | |||
-rw-r--r-- | experimental/tectonics/output.png | bin | 32263 -> 0 bytes | |||
-rw-r--r-- | experimental/tectonics/quadtree.c | 24 | ||||
-rw-r--r-- | experimental/tectonics/tectonics.c | 3 | ||||
-rw-r--r-- | experimental/tectonics/tectonics.h | 2 | ||||
-rw-r--r-- | experimental/tectonics/util.c | 8 | ||||
-rw-r--r-- | experimental/tectonics/util.h | 2 | ||||
-rw-r--r-- | experimental/tectonics/world.c | 21 |
12 files changed, 70 insertions, 63 deletions
diff --git a/experimental/tectonics/Makefile b/experimental/tectonics/Makefile index 877fec1..ab8fb0d 100644 --- a/experimental/tectonics/Makefile +++ b/experimental/tectonics/Makefile @@ -5,8 +5,8 @@ DEPS=tectonics.h %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) -all: world.o util.o tectonics.o quadtree.o - $(CC) -o tectonics world.o util.o tectonics.o quadtree.o $(CFLAGS) +all: world.o util.o tectonics.o quadtree.o drawing.o + $(CC) -o tectonics world.o util.o tectonics.o quadtree.o drawing.o $(CFLAGS) test: all quadtree.o quadtree.test.o tests.o $(CC) -o tests world.o util.o quadtree.o quadtree.test.o tests.o $(CFLAGS) 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); + } +} diff --git a/experimental/tectonics/drawing.h b/experimental/tectonics/drawing.h new file mode 100644 index 0000000..e1a1126 --- /dev/null +++ b/experimental/tectonics/drawing.h @@ -0,0 +1,10 @@ +#ifndef DRAWING_H +#define DRAWING_H + +#include <cairo.h> + +void get_cairo_size(cairo_t *cr, int *width, int *height); +void draw_quadtree(cairo_t *cr, struct quadtree_node_t *root); +void draw_world(cairo_t *cr, struct world_t *world); + +#endif diff --git a/experimental/tectonics/geometry.h b/experimental/tectonics/geometry.h index 09bd7c8..de01042 100644 --- a/experimental/tectonics/geometry.h +++ b/experimental/tectonics/geometry.h @@ -2,7 +2,6 @@ #define GEOMETRY_H #include <stdbool.h> -#include <cairo.h> struct point_t { double x, y; @@ -60,8 +59,6 @@ int quadtree_get_closest(struct quadtree_node_t *root, struct point_t *points, struct point_t pt); -void draw_quadtree(cairo_t *cr, struct quadtree_node_t *root); - /* free a quadtree structure * * note that this will *NOT* free any point userdata! diff --git a/experimental/tectonics/output-relaxed.png b/experimental/tectonics/output-relaxed.png Binary files differdeleted file mode 100644 index f53c0d1..0000000 --- a/experimental/tectonics/output-relaxed.png +++ /dev/null diff --git a/experimental/tectonics/output.png b/experimental/tectonics/output.png Binary files differdeleted file mode 100644 index 1fddaf3..0000000 --- a/experimental/tectonics/output.png +++ /dev/null diff --git a/experimental/tectonics/quadtree.c b/experimental/tectonics/quadtree.c index 820844d..45f11ac 100644 --- a/experimental/tectonics/quadtree.c +++ b/experimental/tectonics/quadtree.c @@ -167,30 +167,6 @@ int quadtree_get_closest(struct quadtree_node_t *node, } -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); - } -} - - void quadtree_free(struct quadtree_node_t *node) { if (node->nw != NULL) { diff --git a/experimental/tectonics/tectonics.c b/experimental/tectonics/tectonics.c index e43a425..7d5342a 100644 --- a/experimental/tectonics/tectonics.c +++ b/experimental/tectonics/tectonics.c @@ -1,6 +1,7 @@ #include <cairo.h> #include "tectonics.h" +#include "drawing.h" #define X_RES 1024 #define Y_RES X_RES @@ -14,7 +15,7 @@ int main() create_world(&world, 10000); if (world.points == NULL) return 1; - render_world(cr, &world); + draw_world(cr, &world); free_world(&world); cairo_destroy(cr); diff --git a/experimental/tectonics/tectonics.h b/experimental/tectonics/tectonics.h index de5b18a..bbde9dd 100644 --- a/experimental/tectonics/tectonics.h +++ b/experimental/tectonics/tectonics.h @@ -3,7 +3,6 @@ #include <stdlib.h> #include <stdbool.h> -#include <cairo.h> #include "geometry.h" @@ -22,7 +21,6 @@ struct world_t { void create_world(struct world_t *world, int n_points); void free_world(struct world_t *world); -void render_world(cairo_t *cr, struct world_t *world); void run_world_step(struct world_t *world); #endif diff --git a/experimental/tectonics/util.c b/experimental/tectonics/util.c index 0bbe880..aa528fb 100644 --- a/experimental/tectonics/util.c +++ b/experimental/tectonics/util.c @@ -3,14 +3,6 @@ #include "util.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); -} - - double rand01() { return ((double) rand())/RAND_MAX; diff --git a/experimental/tectonics/util.h b/experimental/tectonics/util.h index 1a5a505..762229b 100644 --- a/experimental/tectonics/util.h +++ b/experimental/tectonics/util.h @@ -1,10 +1,8 @@ #ifndef UTIL_H #define UTIL_H -#include <cairo.h> #include "geometry.h" -void get_cairo_size(cairo_t *cr, int *width, int *height); double rand01(); double distance(struct point_t p1, struct point_t p2); diff --git a/experimental/tectonics/world.c b/experimental/tectonics/world.c index 5aead24..5aa485c 100644 --- a/experimental/tectonics/world.c +++ b/experimental/tectonics/world.c @@ -131,24 +131,3 @@ void free_world(struct world_t *world) } free(world->points); } - - -/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ - -void render_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)); -} |