1 |
greg |
2.1 |
#ifndef lint |
2 |
greg |
2.4 |
static const char RCSid[] = "$Id$"; |
3 |
greg |
2.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Generate an analog clock. |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
#include <stdio.h> |
9 |
greg |
2.4 |
#include <stdlib.h> |
10 |
greg |
2.1 |
#include <math.h> |
11 |
|
|
#include <ctype.h> |
12 |
|
|
|
13 |
|
|
#define PI 3.14159265358979323846 |
14 |
|
|
|
15 |
|
|
#define FACEBITMAP "clockface.hex" |
16 |
|
|
|
17 |
|
|
char myfacemat[] = "white_plastic"; |
18 |
|
|
double myfacearg[5] = {.85,.85,.85,0,0}; |
19 |
|
|
char mycasemat[] = "black_plastic"; |
20 |
|
|
double mycasearg[5] = {.08,.08,.08,.03,.04}; |
21 |
|
|
char *facemat = myfacemat; |
22 |
|
|
char *casemat = mycasemat; |
23 |
|
|
char *name = "clock"; |
24 |
|
|
|
25 |
|
|
main(argc, argv) |
26 |
|
|
int argc; |
27 |
|
|
char *argv[]; |
28 |
|
|
{ |
29 |
|
|
int i, j; |
30 |
|
|
double hour; |
31 |
|
|
|
32 |
|
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
33 |
|
|
switch (argv[i][1]) { |
34 |
|
|
case 'f': |
35 |
|
|
facemat = argv[++i]; |
36 |
|
|
break; |
37 |
|
|
case 'c': |
38 |
|
|
casemat = argv[++i]; |
39 |
|
|
break; |
40 |
|
|
case 'n': |
41 |
|
|
name = argv[++i]; |
42 |
|
|
break; |
43 |
|
|
default: |
44 |
|
|
goto userr; |
45 |
|
|
} |
46 |
|
|
if (i >= argc) |
47 |
|
|
goto userr; |
48 |
|
|
if (!isdigit(argv[i][0])) |
49 |
|
|
goto userr; |
50 |
|
|
for (j = 1; isdigit(argv[i][j]); j++) |
51 |
|
|
; |
52 |
|
|
if (argv[i][j] == ':') |
53 |
|
|
hour = atoi(argv[i]) + atoi(argv[i]+j+1)/60.0; |
54 |
|
|
else if (!argv[i][j] || argv[i][j] == '.') |
55 |
|
|
hour = atof(argv[i]); |
56 |
|
|
else |
57 |
|
|
goto userr; |
58 |
|
|
putchar('#'); /* print header */ |
59 |
|
|
for (i = 0; i < argc; i++) { |
60 |
|
|
putchar(' '); |
61 |
|
|
fputs(argv[i], stdout); |
62 |
|
|
} |
63 |
|
|
putchar('\n'); |
64 |
|
|
genmats(); /* print materials */ |
65 |
|
|
genclock(); /* generate clock */ |
66 |
|
|
genhands(hour); /* generate hands */ |
67 |
|
|
exit(0); |
68 |
|
|
userr: |
69 |
|
|
fputs("Usage: ", stderr); |
70 |
|
|
fputs(argv[0], stderr); |
71 |
|
|
fputs(" [-f face_mat][-c case_mat][-n name] {HH:MM | HH.hh}\n", stderr); |
72 |
|
|
exit(1); |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
|
76 |
|
|
genmats() /* put out our materials */ |
77 |
|
|
{ |
78 |
|
|
if (facemat == myfacemat) |
79 |
|
|
printf("\nvoid plastic %s\n0\n0\n5 %f %f %f %f %f\n", |
80 |
|
|
myfacemat, myfacearg[0], myfacearg[1], |
81 |
|
|
myfacearg[2], myfacearg[3], myfacearg[4]); |
82 |
|
|
if (casemat == mycasemat) |
83 |
|
|
printf("\nvoid plastic %s\n0\n0\n5 %f %f %f %f %f\n", |
84 |
|
|
mycasemat, mycasearg[0], mycasearg[1], |
85 |
|
|
mycasearg[2], mycasearg[3], mycasearg[4]); |
86 |
|
|
printf("\n%s brighttext clock_face_paint\n2 hexbit4x1.fnt %s\n", |
87 |
|
|
facemat, FACEBITMAP); |
88 |
|
|
printf("0\n11\n\t0\t-1\t1\n\t0\t.0185\t0\n\t0\t0\t-.00463\n"); |
89 |
|
|
printf("\t.02\t1\n"); |
90 |
|
|
printf("\nvoid glass clock_crystal\n0\n0\n3 .95 .95 .95\n"); |
91 |
|
|
printf("\nvoid plastic hand_paint\n0\n0\n5 .03 .03 .03 0 0\n"); |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
|
95 |
|
|
genclock() /* put out clock body */ |
96 |
|
|
{ |
97 |
|
|
printf("\n%s ring %s.case_back\n", casemat, name); |
98 |
|
|
printf("0\n0\n8\t0\t0\t0\n\t-1\t0\t0\n\t0\t1.1\n"); |
99 |
|
|
printf("\n%s cylinder %s.case_outer\n", casemat, name); |
100 |
|
|
printf("0\n0\n7\t0\t0\t0\n\t.12\t0\t0\n\t1.1\n"); |
101 |
|
|
printf("\n%s ring %s.case_front\n", casemat, name); |
102 |
|
|
printf("0\n0\n8\t.12\t0\t0\n\t1\t0\t0\n\t1\t1.1\n"); |
103 |
|
|
printf("\n%s cylinder %s.case_inner\n", casemat, name); |
104 |
greg |
2.3 |
printf("0\n0\n7\t.05\t0\t0\n\t.12\t0\t0\n\t1\n"); |
105 |
greg |
2.1 |
printf("\nclock_crystal ring %s.crystal\n", name); |
106 |
|
|
printf("0\n0\n8\t.10\t0\t0\n\t1\t0\t0\n\t0\t1\n"); |
107 |
|
|
printf("\nclock_face_paint ring %s.face\n", name); |
108 |
|
|
printf("0\n0\n8\t.05\t0\t0\n\t1\t0\t0\n\t0\t1\n"); |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
|
112 |
|
|
genhands(hour) /* generate correct hand positions */ |
113 |
|
|
double hour; |
114 |
|
|
{ |
115 |
|
|
double hrot, mrot; |
116 |
|
|
|
117 |
|
|
hrot = 2.*PI/12. * hour; |
118 |
|
|
mrot = 2.*PI * (hour - floor(hour)); |
119 |
|
|
|
120 |
|
|
printf("\nhand_paint polygon %s.hour_hand\n", name); |
121 |
|
|
printf("0\n0\n12\n"); |
122 |
greg |
2.2 |
rvert(.06, -.03, -.06, hrot); |
123 |
|
|
rvert(.06, .03, -.06, hrot); |
124 |
greg |
2.1 |
rvert(.06, .025, .5, hrot); |
125 |
|
|
rvert(.06, -.025, .5, hrot); |
126 |
|
|
|
127 |
|
|
printf("\nhand_paint polygon %s.minute_hand\n", name); |
128 |
|
|
printf("0\n0\n12\n"); |
129 |
greg |
2.2 |
rvert(.07, -.02, -.1, mrot); |
130 |
|
|
rvert(.07, .02, -.1, mrot); |
131 |
greg |
2.1 |
rvert(.07, .01, .9, mrot); |
132 |
|
|
rvert(.07, -.01, .9, mrot); |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
|
136 |
|
|
rvert(x, y, z, ang) /* print rotated vertex */ |
137 |
|
|
double x, y, z, ang; |
138 |
|
|
{ |
139 |
greg |
2.2 |
static double lastang=0, sa=0, ca=1; |
140 |
greg |
2.1 |
|
141 |
greg |
2.2 |
if (ang != lastang) { |
142 |
|
|
sa = sin(-ang); |
143 |
|
|
ca = cos(-ang); |
144 |
|
|
lastang = ang; |
145 |
|
|
} |
146 |
greg |
2.1 |
printf("%15.12g %15.12g %15.12g\n", x, y*ca-z*sa, z*ca+y*sa); |
147 |
|
|
} |