-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathop_moire.c
95 lines (76 loc) · 2.28 KB
/
op_moire.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* op_moire --- draw moire op-art pattern 2014-06-01 */
/* Copyright (c) 2014 John Honniball, Froods Software Development */
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
#include "hpgllib.h"
void draw_diagonals(int nlines, double pitch, double xl, double xr,
double yoff1, double dyoff1, double yoff2, double dyoff2);
int main(int argc, char * const argv[])
{
/* Optical and Geometrical Allover Patterns, by Jean Larcher,
1979, ISBN: 0-486-23758-3 */
int opt;
int nlines;
double xc;
double scale = 40.0;
double maxx, maxy;
double xl, xr;
double height;
const double yoff = 10.0 * scale;
const double pitch = 2.0 * scale;
double dyoff;
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(0) < 0) {
fputs("Failed to initialise HPGL library\n", stderr);
exit(EXIT_FAILURE);
}
getplotsize(&maxx, &maxy);
xc = maxx / 2.0;
height = maxy;
xl = xc - height / 2.0;
xr = xc + height / 2.0;
nlines = ((height - (yoff + (5.0 * scale))) / pitch) + 1;
dyoff = (5.0 * scale) / (double)nlines;
/* Draw square border */
rectangle(xc - (height / 2.0), 0.0, xc + (height / 2.0), maxy);
draw_diagonals(nlines, pitch, xl, xr, yoff, dyoff, 0.0, 0.0);
draw_diagonals(nlines, pitch, xl, xr, 0.0, 0.0, yoff, dyoff);
plotend();
return (0);
}
void draw_diagonals(int nlines, double pitch, double xl, double xr,
double yoff1, double dyoff1, double yoff2, double dyoff2)
{
int i;
double y;
/* Draw array of sloped lines */
for (y = 0.0, i = 0; i < nlines; y += pitch, i++) {
if (i & 1) {
moveto(xl, y + yoff1);
lineto(xr, y + yoff2);
}
else {
moveto(xr, y + yoff2);
lineto(xl, y + yoff1);
}
yoff1 += dyoff1;
yoff2 += dyoff2;
}
}