From 83f1bf37b77899defc5502c22e2bebb029deb0fe Mon Sep 17 00:00:00 2001 From: John Honniball Date: Thu, 27 Aug 2020 21:27:28 +0100 Subject: [PATCH] New drawing: cutout_hex, hexagons that are intended to be cut out from the page. Note that they don't make the most efficient use of the paper -- they don't tesselate. But they can be cut apart using a knife and straightedge. --- .gitignore | 1 + Makefile | 11 ++++- cutout_hex.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 cutout_hex.c diff --git a/.gitignore b/.gitignore index 8c6299a..a3bb7c1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ arches celticstep circle4 circle_lines +cutout_hex coords coords-nc cs_rosette diff --git a/Makefile b/Makefile index 1e02d5b..0f823c2 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ HPGL=flake.hpgl op.hpgl dala1.hpgl hconic2.hpgl tree.hpgl dome.hpgl \ morphpoly.hpgl pin_circle.hpgl isogrid.hpgl circle_lines.hpgl \ star_grid.hpgl ternary_arcs.hpgl hexspiral.hpgl poly_oval.hpgl \ libtest.hpgl linetiles.hpgl a6cardlabels.hpgl octoflower.hpgl \ - circle4.hpgl truchet1.hpgl + circle4.hpgl truchet1.hpgl cutout_hex.hpgl SVG=$(HPGL:.hpgl=.svg) @@ -85,6 +85,15 @@ circle_lines: circle_lines.o hpgllib.o circle_lines.o: circle_lines.c hpgllib.h $(CC) $(CFLAGS) -o $@ circle_lines.c +cutout_hex.hpgl: cutout_hex Makefile + ./cutout_hex $(TITLE) $(BOLDPEN) -o $@ + +cutout_hex: cutout_hex.o hpgllib.o + $(LD) -o $@ cutout_hex.o hpgllib.o -lm + +cutout_hex.o: cutout_hex.c hpgllib.h + $(CC) $(CFLAGS) -o $@ cutout_hex.c + ellipse.hpgl: ellipse Makefile ./ellipse $(TITLE) $(BOLDPEN) -o $@ diff --git a/cutout_hex.c b/cutout_hex.c new file mode 100644 index 0000000..eafcdc3 --- /dev/null +++ b/cutout_hex.c @@ -0,0 +1,117 @@ +/* cutout_hex --- plot hexagons that can be cut out easily 2020-08-26 */ +/* Copyright (c) 2020 John Honniball, Froods Software Development */ + +#include +#include +#include +#include +#include +#include "hpgllib.h" + +#define RADIANS (M_PI / 180.0) + +void hexgrid(const double side, const int nx, const int ny); + +int main(int argc, char * const argv[]) +{ + int opt; + double side; + double maxx, maxy; + + while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) { + switch (opt) { + case 's': + case 'n': + case 'o': + case 'p': + case 't': + case 'v': + plotopt(opt, optarg); + break; + default: /* '?' */ + fprintf(stderr, "Usage: %s [-p pen] [-s ] [-t title]\n", argv[0]); + fprintf(stderr, " ::= A1 | A2 | A3 | A4 | A5\n"); + exit(EXIT_FAILURE); + } + } + + if (plotbegin(1) < 0) { + fputs("Failed to initialise HPGL library\n", stderr); + exit(EXIT_FAILURE); + } + + getplotsize(&maxx, &maxy); + +// side = 50.08 * 40.0; +// hexgrid(side, 4, 2); + side = 45.0 * 40.0; + hexgrid(side, 5, 3); + + plotend(); + + return (0); +} + + +void hexgrid(const double side, const int nx, const int ny) +{ + int i, j; + const double width = 2.0 * side * cos(30.0 * RADIANS); + + for (i = 0; i < ny; i++) { + const double y = 2.0 * side * (double)i; + const double y1 = y + (side * sin(30.0 * RADIANS)); +#ifdef TRISECT + const double y2 = y + side; +#endif + const double y3 = y1 + side; + const double y4 = y + (2.0 * side); + + for (j = 0; j < nx; j++) { + const double x = width * (double)j; + const double x1 = x + (side * cos(30 * RADIANS)); + const double x2 = x + width; + + moveto(x, y1); + lineto(x1, y); + lineto(x2, y1); + } + + for (j = 0; j < (nx + 1); j++) { + const double x = width * (double)j; + + moveto(x, y1); + lineto(x, y3); + } + + for (j = 0; j < nx; j++) { + const double x = width * (double)j; + const double x1 = x + (side * cos(30 * RADIANS)); + const double x2 = x + width; + + moveto(x, y3); + lineto(x1, y4); + lineto(x2, y3); + } + +#ifdef TRISECT + for (j = 0; j < nx; j++) { + const double x = width * (double)j; + const double x1 = x + (side * cos(30 * RADIANS)); + const double x2 = x + width; + + moveto(x, y1); + lineto(x1, y2); + lineto(x2, y1); + } + + for (j = 0; j < nx; j++) { + const double x = width * (double)j; + const double x1 = x + (side * cos(30 * RADIANS)); + + moveto(x1, y2); + lineto(x1, y4); + } +#endif + } +}