aboutsummaryrefslogtreecommitdiffstats
path: root/demo.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--demo.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/demo.c b/demo.c
new file mode 100644
index 0000000..76473e7
--- /dev/null
+++ b/demo.c
@@ -0,0 +1,91 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+
+int
+main(void)
+{
+#define P(I) (points[I].x - 0), (points[I].y - 0)
+ /* TODO test drawing outside of raster */
+
+ RTGRPBLIB_RASTER *raster;
+ double *image;
+ size_t x, y, i, j, n;
+ size_t width = 40;
+ size_t height = 30;
+ struct {
+ double x, y;
+ } points[] = {
+#if 0
+ {20, 5},
+ {30, 15},
+ {20, 25},
+ {10, 15}
+#elif 0
+ {20, 5},
+ {35, 15},
+ {20, 25},
+ {5, 15}
+#else
+ {5.25, 5.25},
+ {35.75, 5.25},
+ {35.75, 25.75},
+ {5.25, 25.75}
+#endif
+ };
+
+ raster = rtgrpblib_create_raster(width, height);
+ image = calloc(width * height, sizeof(*image));
+
+#if 0
+ n = sizeof(points) / sizeof(*points);
+ for (i = 0; i < n; i++) {
+ j = (i + 1) % n;
+ rtgrpblib_draw_linear_bezier(raster, P(i), P(j));
+ }
+#elif 0
+ rtgrpblib_draw_quadratic_bezier(raster, P(2), P(3), P(0));
+ rtgrpblib_draw_linear_bezier(raster, P(0), P(2));
+#else
+ rtgrpblib_draw_cubic_bezier(raster, P(0), P(1), P(2), P(3));
+ rtgrpblib_draw_linear_bezier(raster, P(3), P(0));
+#endif
+
+ rtgrpblib_fill_shapes(image, width, raster);
+
+#if 1
+ printf("\nOutline (area)\n");
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++)
+ printf(raster->cells[y * width + x].cell_coverage ? "%+.1lf " : " 0 ",
+ raster->cells[y * width + x].cell_coverage);
+ printf("\n");
+ }
+ printf("\nOutline (shadow)\n");
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++)
+ printf(raster->cells[y * width + x].opposite_coverage ? "%+.1lf " : " 0 ",
+ raster->cells[y * width + x].opposite_coverage);
+ printf("\n");
+ }
+ printf("\nFill\n");
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ unsigned val = (unsigned)(image[y * width + x] * 255 + 0.5);
+ printf("%02X ", val - (val == 128));
+ }
+ printf("\n");
+ }
+#else
+ printf("P2\n# %s\n%zu %zu\n255\n", "Note: no gamma correction applied", width, height);
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++)
+ printf("%i ", (int)(image->cells[y * width + x] * 255 + 0.5));
+ printf("\n");
+ }
+#endif
+
+ free(raster);
+ free(image);
+ return 0;
+}