diff options
Diffstat (limited to 'src/cairo-shapes.cpp')
| -rw-r--r-- | src/cairo-shapes.cpp | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/cairo-shapes.cpp b/src/cairo-shapes.cpp index a5dd56a..6f7cbfe 100644 --- a/src/cairo-shapes.cpp +++ b/src/cairo-shapes.cpp @@ -6,6 +6,19 @@ #include <math.h> #include "cairo-shapes.h" +static int star_points[11][2] = { + { 0, 85 }, + { 75, 75 }, + { 100, 10 }, + { 125, 75 }, + { 200, 85 }, + { 150, 125 }, + { 160, 190 }, + { 100, 150 }, + { 40, 190 }, + { 50, 125 }, + { 0, 85 } +}; void cairoRandomizeColor(caskbench_context_t *ctx) @@ -32,17 +45,37 @@ void cairoDrawRectangle(caskbench_context_t *ctx, shapes_t *args) void cairoDrawTriangle(caskbench_context_t *ctx, shapes_t *args) { - for (int p = 0; p < args->numpoints; p++ ) { + ctx->shape_args.numpoints = 3; + ctx->shape_args.points = (double (*)[2]) malloc(ctx->shape_args.numpoints*2*(sizeof(double))); + ctx->shape_args.points[0][0] = ctx->shape_args.centre_x; + ctx->shape_args.points[0][1] = ctx->shape_args.centre_y+2*ctx->shape_args.radius; + ctx->shape_args.points[1][0] = 2*ctx->shape_args.radius; + ctx->shape_args.points[1][1] = 0; + ctx->shape_args.points[2][0] = -ctx->shape_args.radius; + ctx->shape_args.points[2][1] = -2*ctx->shape_args.radius; + + + for (int p = 0; p < 3; p++ ) { if(p == 0) cairo_move_to (ctx->cairo_cr, args->points[p][0], args->points[0][1]); else cairo_rel_line_to (ctx->cairo_cr, args->points[p][0], args->points[p][1]); } - + free (ctx->shape_args.points); } void cairoDrawStar(caskbench_context_t *ctx, shapes_t *args) { + ctx->shape_args.numpoints = 10; + ctx->shape_args.points = (double (*)[2]) malloc(ctx->shape_args.numpoints*2*(sizeof(double))); + + for (int p = 0; p < 10; p++ ) { + int px = ctx->shape_args.centre_x + 2*ctx->shape_args.radius * star_points[p][0]/200.0; + int py = ctx->shape_args.centre_y + 2*ctx->shape_args.radius * star_points[p][1]/200.0; + ctx->shape_args.points[p][0] = px; + ctx->shape_args.points[p][1] = py; + } + for (int p = 0; p < args->numpoints; p++ ) { if(p == 0) cairo_move_to (ctx->cairo_cr, args->points[p][0], args->points[0][1]); @@ -50,6 +83,7 @@ void cairoDrawStar(caskbench_context_t *ctx, shapes_t *args) cairo_line_to (ctx->cairo_cr, args->points[p][0], args->points[p][1]); } cairo_close_path(ctx->cairo_cr); + free (ctx->shape_args.points); } |