10 |
|
|
11 |
|
#include <stdio.h> |
12 |
|
|
13 |
+ |
#include "color.h" |
14 |
+ |
|
15 |
|
#define PI 3.14159265358979323846 |
16 |
|
|
17 |
|
extern char *gets(), *strcpy(); |
29 |
|
|
30 |
|
float *lampcolor; /* the lamp color (RGB) */ |
31 |
|
double unit2meter; /* conversion from units to meters */ |
32 |
< |
double projarea; /* projected area for this geometry */ |
32 |
> |
double area; /* radiating area for this geometry */ |
33 |
|
double lumens; /* total lamp lumens */ |
34 |
|
|
35 |
|
struct { |
175 |
|
{ |
176 |
|
double whiteval; |
177 |
|
|
178 |
< |
whiteval = lumens/470./projarea; |
178 |
> |
whiteval = lumens/area/(WHTEFFICACY*PI); |
179 |
|
|
180 |
|
printf("Lamp color (RGB) = %f %f %f\n", |
181 |
|
lampcolor[0]*whiteval, |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
< |
getd(dp) /* get a positive double from stdin */ |
187 |
> |
getd(name, dp, help) /* get a positive double from stdin */ |
188 |
> |
char *name; |
189 |
|
double *dp; |
190 |
+ |
char *help; |
191 |
|
{ |
192 |
|
char buf[32]; |
193 |
< |
|
193 |
> |
again: |
194 |
> |
printf("%s [%g]: ", name, *dp); |
195 |
|
if (gets(buf) == NULL) |
196 |
|
return(0); |
197 |
+ |
if (buf[0] == '?') { |
198 |
+ |
puts(help); |
199 |
+ |
goto again; |
200 |
+ |
} |
201 |
|
if ((buf[0] < '0' || buf[0] > '9') && buf[0] != '.') |
202 |
|
return(0); |
203 |
|
*dp = atof(buf); |
209 |
|
{ |
210 |
|
static double area = 1.0; |
211 |
|
|
212 |
< |
printf("Polygon area [%g]: ", area); |
213 |
< |
getd(&area); |
214 |
< |
projarea = PI*unit2meter*unit2meter * area; |
212 |
> |
getd("Polygon area", &area, |
213 |
> |
"Enter the total radiating area of the polygon."); |
214 |
> |
area = unit2meter*unit2meter * area; |
215 |
|
return(1); |
216 |
|
} |
217 |
|
|
220 |
|
{ |
221 |
|
static double radius = 1.0; |
222 |
|
|
223 |
< |
printf("Sphere radius [%g]: ", radius); |
224 |
< |
getd(&radius); |
225 |
< |
projarea = 4.*PI*PI*unit2meter*unit2meter * radius*radius; |
223 |
> |
getd("Sphere radius", &radius, |
224 |
> |
"Enter the distance from the sphere's center to its surface."); |
225 |
> |
area = 4.*PI*unit2meter*unit2meter * radius*radius; |
226 |
|
return(1); |
227 |
|
} |
228 |
|
|
231 |
|
{ |
232 |
|
static double length = 1.0, radius = 0.1; |
233 |
|
|
234 |
< |
printf("Cylinder length [%g]: ", length); |
235 |
< |
getd(&length); |
236 |
< |
printf("Cylinder radius [%g]: ", radius); |
237 |
< |
getd(&radius); |
238 |
< |
projarea = PI*PI*2.*PI*unit2meter*unit2meter * radius*length; |
234 |
> |
getd("Cylinder length", &length, |
235 |
> |
"Enter the length of the cylinder."); |
236 |
> |
getd("Cylinder radius", &radius, |
237 |
> |
"Enter the distance from the cylinder's axis to its surface."); |
238 |
> |
area = 2.*PI*unit2meter*unit2meter * radius*length; |
239 |
|
return(1); |
240 |
|
} |
241 |
|
|
244 |
|
{ |
245 |
|
static double radius = 1.0; |
246 |
|
|
247 |
< |
printf("Disk radius [%g]: ", radius); |
248 |
< |
getd(&radius); |
249 |
< |
projarea = PI*PI*unit2meter*unit2meter * radius*radius; |
247 |
> |
getd("Disk radius", &radius, |
248 |
> |
"Enter the distance from the ring's center to its outer edge.\n\ |
249 |
> |
The inner radius must be zero."); |
250 |
> |
area = PI*unit2meter*unit2meter * radius*radius; |
251 |
|
return(1); |
252 |
|
} |