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); |
207 |
|
|
208 |
|
getpolygon() /* get projected area for a polygon */ |
209 |
|
{ |
210 |
< |
printf("Enter area of polygon: "); |
211 |
< |
if (!getd(&projarea)) |
212 |
< |
return(0); |
213 |
< |
projarea *= unit2meter*unit2meter; |
214 |
< |
projarea *= PI; |
210 |
> |
static double parea = 1.0; |
211 |
> |
|
212 |
> |
getd("Polygon area", &parea, |
213 |
> |
"Enter the total radiating area of the polygon."); |
214 |
> |
area = unit2meter*unit2meter * parea; |
215 |
|
return(1); |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
getsphere() /* get projected area for a sphere */ |
220 |
|
{ |
221 |
< |
double radius; |
221 |
> |
static double radius = 1.0; |
222 |
|
|
223 |
< |
printf("Enter sphere radius: "); |
224 |
< |
if (!getd(&radius)) |
225 |
< |
return(0); |
217 |
< |
radius *= unit2meter; |
218 |
< |
projarea = 4.*PI*PI*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 |
|
|
229 |
|
|
230 |
|
getcylinder() /* get projected area for a cylinder */ |
231 |
|
{ |
232 |
< |
double length, radius; |
232 |
> |
static double length = 1.0, radius = 0.1; |
233 |
|
|
234 |
< |
printf("Enter cylinder length: "); |
235 |
< |
if (!getd(&length)) |
236 |
< |
return(0); |
237 |
< |
length *= unit2meter; |
238 |
< |
printf("Enter cylinder radius: "); |
232 |
< |
if (!getd(&radius)) |
233 |
< |
return(0); |
234 |
< |
radius *= unit2meter; |
235 |
< |
projarea = PI*PI*2.*PI*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 |
|
|
242 |
|
|
243 |
|
getring() /* get projected area for a ring */ |
244 |
|
{ |
245 |
< |
double radius; |
245 |
> |
static double radius = 1.0; |
246 |
|
|
247 |
< |
printf("Enter disk radius: "); |
248 |
< |
if (!getd(&radius)) |
249 |
< |
return(0); |
250 |
< |
radius *= unit2meter; |
248 |
< |
projarea = PI*PI*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 |
|
} |