Skip to content

Commit

Permalink
New drawing: cutout_hex, hexagons that are intended to be cut out fro…
Browse files Browse the repository at this point in the history
…m 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.
  • Loading branch information
anachrocomputer committed Aug 27, 2020
1 parent f5c7a16 commit 83f1bf3
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ arches
celticstep
circle4
circle_lines
cutout_hex
coords
coords-nc
cs_rosette
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 $@

Expand Down
117 changes: 117 additions & 0 deletions cutout_hex.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#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 <size>] [-t title]\n", argv[0]);
fprintf(stderr, " <size> ::= 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
}
}

0 comments on commit 83f1bf3

Please sign in to comment.