1 |
– |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Generate an analog clock. |
6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdio.h> |
9 |
+ |
#include <stdlib.h> |
10 |
|
#include <math.h> |
11 |
|
#include <ctype.h> |
12 |
|
|
13 |
|
#define PI 3.14159265358979323846 |
14 |
|
|
17 |
– |
#ifdef DCL_ATOF |
18 |
– |
extern double atof(); |
19 |
– |
#endif |
20 |
– |
|
15 |
|
#define FACEBITMAP "clockface.hex" |
16 |
|
|
17 |
|
char myfacemat[] = "white_plastic"; |
22 |
|
char *casemat = mycasemat; |
23 |
|
char *name = "clock"; |
24 |
|
|
25 |
< |
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 |
< |
|
25 |
> |
static void |
26 |
|
genmats() /* put out our materials */ |
27 |
|
{ |
28 |
|
if (facemat == myfacemat) |
42 |
|
} |
43 |
|
|
44 |
|
|
45 |
+ |
static void |
46 |
|
genclock() /* put out clock body */ |
47 |
|
{ |
48 |
|
printf("\n%s ring %s.case_back\n", casemat, name); |
52 |
|
printf("\n%s ring %s.case_front\n", casemat, name); |
53 |
|
printf("0\n0\n8\t.12\t0\t0\n\t1\t0\t0\n\t1\t1.1\n"); |
54 |
|
printf("\n%s cylinder %s.case_inner\n", casemat, name); |
55 |
< |
printf("0\n0\n7\t.05\t0\t0\n\t.15\t0\t0\n\t1\n"); |
55 |
> |
printf("0\n0\n7\t.05\t0\t0\n\t.12\t0\t0\n\t1\n"); |
56 |
|
printf("\nclock_crystal ring %s.crystal\n", name); |
57 |
|
printf("0\n0\n8\t.10\t0\t0\n\t1\t0\t0\n\t0\t1\n"); |
58 |
|
printf("\nclock_face_paint ring %s.face\n", name); |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
+ |
static void |
64 |
+ |
rvert(x, y, z, ang) /* print rotated vertex */ |
65 |
+ |
double x, y, z, ang; |
66 |
+ |
{ |
67 |
+ |
static double lastang=0, sa=0, ca=1; |
68 |
+ |
|
69 |
+ |
if (ang != lastang) { |
70 |
+ |
sa = sin(-ang); |
71 |
+ |
ca = cos(-ang); |
72 |
+ |
lastang = ang; |
73 |
+ |
} |
74 |
+ |
printf("%15.12g %15.12g %15.12g\n", x, y*ca-z*sa, z*ca+y*sa); |
75 |
+ |
} |
76 |
+ |
|
77 |
+ |
|
78 |
+ |
static void |
79 |
|
genhands(hour) /* generate correct hand positions */ |
80 |
|
double hour; |
81 |
|
{ |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
< |
rvert(x, y, z, ang) /* print rotated vertex */ |
104 |
< |
double x, y, z, ang; |
103 |
> |
int |
104 |
> |
main(argc, argv) |
105 |
> |
int argc; |
106 |
> |
char *argv[]; |
107 |
|
{ |
108 |
< |
static double lastang=0, sa=0, ca=1; |
108 |
> |
int i, j; |
109 |
> |
double hour; |
110 |
|
|
111 |
< |
if (ang != lastang) { |
112 |
< |
sa = sin(-ang); |
113 |
< |
ca = cos(-ang); |
114 |
< |
lastang = ang; |
111 |
> |
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
112 |
> |
switch (argv[i][1]) { |
113 |
> |
case 'f': |
114 |
> |
facemat = argv[++i]; |
115 |
> |
break; |
116 |
> |
case 'c': |
117 |
> |
casemat = argv[++i]; |
118 |
> |
break; |
119 |
> |
case 'n': |
120 |
> |
name = argv[++i]; |
121 |
> |
break; |
122 |
> |
default: |
123 |
> |
goto userr; |
124 |
> |
} |
125 |
> |
if (i >= argc) |
126 |
> |
goto userr; |
127 |
> |
if (!isdigit(argv[i][0])) |
128 |
> |
goto userr; |
129 |
> |
for (j = 1; isdigit(argv[i][j]); j++) |
130 |
> |
; |
131 |
> |
if (argv[i][j] == ':') |
132 |
> |
hour = atoi(argv[i]) + atoi(argv[i]+j+1)/60.0; |
133 |
> |
else if (!argv[i][j] || argv[i][j] == '.') |
134 |
> |
hour = atof(argv[i]); |
135 |
> |
else |
136 |
> |
goto userr; |
137 |
> |
putchar('#'); /* print header */ |
138 |
> |
for (i = 0; i < argc; i++) { |
139 |
> |
putchar(' '); |
140 |
> |
fputs(argv[i], stdout); |
141 |
|
} |
142 |
< |
printf("%15.12g %15.12g %15.12g\n", x, y*ca-z*sa, z*ca+y*sa); |
142 |
> |
putchar('\n'); |
143 |
> |
genmats(); /* print materials */ |
144 |
> |
genclock(); /* generate clock */ |
145 |
> |
genhands(hour); /* generate hands */ |
146 |
> |
exit(0); |
147 |
> |
userr: |
148 |
> |
fputs("Usage: ", stderr); |
149 |
> |
fputs(argv[0], stderr); |
150 |
> |
fputs(" [-f face_mat][-c case_mat][-n name] {HH:MM | HH.hh}\n", stderr); |
151 |
> |
exit(1); |
152 |
|
} |
153 |
+ |
|