-
Notifications
You must be signed in to change notification settings - Fork 4
/
coords.c
90 lines (71 loc) · 1.93 KB
/
coords.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
/* coords --- plot an HPGL coordinate chart 2010-09-07 */
/* Copyright (c) 2010 John Honniball, Froods Software Development */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "hpgllib.h"
int main(int argc, char * const argv[])
{
int opt;
int i;
char str[32];
int ix, iy;
double xc, yc;
double radius;
double small, big;
double maxx, maxy;
while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
switch (opt) {
case 'n':
case 'o':
case 'p':
case 's':
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);
xc = maxx / 2.0;
yc = maxy / 2.0;
radius = maxy - yc;
/* Plot centrelines */
moveto(0.0, yc);
lineto(maxx, yc);
moveto(xc, 0.0);
lineto(xc, maxy);
/* Ticks on X-axis */
small = 800.0;
big = ((int)(maxx / 800.0)) * 800.0;
for (i = small; i <= big; i += 800) {
moveto((double)i, 0.0);
lineto((double)i, 200.0);
ix = getdevx((double)i);
sprintf(str, "%d %dmm", ix, i / 40);
vlabel((double)(i + 100), 300.0, 5.0, str);
}
/* Ticks on Y-axis */
small = 800.0;
big = ((int)(maxy / 800.0)) * 800.0;
for (i = small; i <= big; i += 800) {
moveto(0.0, (double)i);
lineto(200.0, (double)i);
iy = getdevy((double)i);
sprintf(str, "%d %dmm", iy, i / 40);
hlabel(300.0, (double)(i - 100), 5.0, str);
}
/* Plot main circles */
circle(xc, yc, radius);
circle(xc, yc, radius / 2.0);
plotend();
return (0);
}