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