summaryrefslogtreecommitdiffstatsci
path: root/src/stroke.cpp
diff options
context:
space:
mode:
authorBryce Harrington <b.harrington@samsung.com>2013-10-28 11:49:00 -0700
committerBryce Harrington <b.harrington@samsung.com>2013-10-28 12:48:31 -0700
commit8ce2e4d7e4bdd5a0252affe02c17a1929d46bb53 (patch)
tree4ca6061764492962ed732e100fb140d9adaf5617 /src/stroke.cpp
parent05326d97cf27db6c55cf7746f491930dd0317b28 (diff)
Convert test cases from C to C++
Diffstat (limited to 'src/stroke.cpp')
-rw-r--r--src/stroke.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/stroke.cpp b/src/stroke.cpp
new file mode 100644
index 0000000..2959125
--- /dev/null
+++ b/src/stroke.cpp
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <cairo.h>
+
+void
+randomize_color(cairo_t *cr)
+{
+ double red, green, blue, alpha;
+
+ red = (double)rand()/RAND_MAX;
+ green = (double)rand()/RAND_MAX;
+ blue = (double)rand()/RAND_MAX;
+ alpha = (double)rand()/RAND_MAX;
+
+ cairo_set_source_rgba (cr, red, green, blue, alpha);
+}
+
+int
+main(int argc, char *argv[]) {
+ int i, x, w, prev_w;
+ cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 800, 80);
+ cairo_t *cr = cairo_create (surface);
+
+ srand(0xdeadbeef);
+
+ x = 0;
+ prev_w = 0;
+ for (i=0; i<32; i++) {
+ randomize_color (cr);
+ w = (32.0*rand())/RAND_MAX + 1;
+ x += 4 + (prev_w + w)/2.0;
+ cairo_move_to (cr, x, 10);
+ cairo_line_to (cr, x, 70);
+ cairo_set_line_width (cr, w);
+ cairo_stroke (cr);
+ prev_w = w;
+ }
+
+ cairo_destroy (cr);
+ cairo_surface_write_to_png (surface, "hello.png");
+ cairo_surface_destroy (surface);
+ return 0;
+}
+