@@ -74,7 +74,11 @@ fn main() -> io::Result<()> {
74
74
let mut rng = rand:: thread_rng ( ) ;
75
75
for i in 0 ..args. particles {
76
76
if i % 100 == 0 {
77
- print ! ( "\r generated {} particles, progress: {}%" , i, i * 100 / args. particles) ;
77
+ print ! (
78
+ "\r generated {} particles, progress: {}%" ,
79
+ i,
80
+ i * 100 / args. particles
81
+ ) ;
78
82
io:: stdout ( ) . flush ( ) ?;
79
83
}
80
84
@@ -117,7 +121,14 @@ It contains {} particles and its bounding box goes from
117
121
Ok ( ( ) )
118
122
}
119
123
120
- fn save_pov_scene ( path : & Path , Scene { dla, camera, lights } : & Scene ) -> io:: Result < ( ) > {
124
+ fn save_pov_scene (
125
+ path : & Path ,
126
+ Scene {
127
+ dla,
128
+ camera,
129
+ lights,
130
+ } : & Scene ,
131
+ ) -> io:: Result < ( ) > {
121
132
let path = path. with_extension ( "pov" ) ;
122
133
let mut out = BufWriter :: new ( File :: create ( & path) ?) ;
123
134
@@ -161,17 +172,26 @@ camera {{
161
172
}
162
173
163
174
let center = bbox. center ( ) ;
164
- let mut cells = dla. cells ( ) . map ( |cc| ( cc, center. dist2 ( * cc) ) ) . collect :: < Vec < _ > > ( ) ;
175
+ let mut cells = dla
176
+ . cells ( )
177
+ . map ( |cc| ( cc, center. dist2 ( * cc) ) )
178
+ . collect :: < Vec < _ > > ( ) ;
165
179
cells. sort_by_key ( |( _, d) | * d) ;
166
180
167
- let max_d = cells. last ( ) . expect ( "empty dla, cannot happen since it should be seeded" ) . 1 ;
181
+ let max_d = cells
182
+ . last ( )
183
+ . expect ( "empty dla, cannot happen since it should be seeded" )
184
+ . 1 ;
168
185
let mut cells = cells. into_iter ( ) ;
169
186
170
187
let gradients = 3 ;
171
188
let n = gradients * 2 ;
172
189
for i in 0 ..n {
173
190
writeln ! ( out, "\n union {{" ) ?;
174
- for ( p, _) in cells. by_ref ( ) . take_while ( |( _, dd) | * dd <= ( i + 1 ) * max_d / n) {
191
+ for ( p, _) in cells
192
+ . by_ref ( )
193
+ . take_while ( |( _, dd) | * dd <= ( i + 1 ) * max_d / n)
194
+ {
175
195
writeln ! ( out, " sphere {{ <{}, {}, {}>, 1 }}" , p. x, p. y, p. z) ?;
176
196
}
177
197
@@ -211,7 +231,14 @@ render with a command like the following
211
231
Ok ( ( ) )
212
232
}
213
233
214
- fn save_js_scene ( path : & Path , Scene { dla, camera, lights } : & Scene ) -> io:: Result < ( ) > {
234
+ fn save_js_scene (
235
+ path : & Path ,
236
+ Scene {
237
+ dla,
238
+ camera,
239
+ lights,
240
+ } : & Scene ,
241
+ ) -> io:: Result < ( ) > {
215
242
let path = path. with_extension ( "js" ) ;
216
243
let mut out = BufWriter :: new ( File :: create ( & path) ?) ;
217
244
@@ -299,7 +326,10 @@ impl Scene {
299
326
fn new ( dla : Dla ) -> Self {
300
327
let scene_bbox = dla. bbox ( ) ;
301
328
let scene_dimensions = scene_bbox. dimensions ( ) ;
302
- let away_dist = scene_dimensions. x . min ( scene_dimensions. y ) . min ( scene_dimensions. z ) ;
329
+ let away_dist = scene_dimensions
330
+ . x
331
+ . min ( scene_dimensions. y )
332
+ . min ( scene_dimensions. z ) ;
303
333
304
334
let camera = Camera {
305
335
position : Vec3 :: new (
@@ -313,12 +343,19 @@ impl Scene {
313
343
let mut lights = vec ! [ ] ;
314
344
let mut add_light = |pt : Vec3 , intensity| {
315
345
let position = pt + ( pt - scene_bbox. center ( ) ) . normalized ( ) * away_dist;
316
- lights. push ( Light { position, intensity } )
346
+ lights. push ( Light {
347
+ position,
348
+ intensity,
349
+ } )
317
350
} ;
318
351
319
352
// key light
320
353
add_light (
321
- Vec3 :: new ( scene_bbox. lower ( ) . x , scene_bbox. center ( ) . y , scene_bbox. lower ( ) . z ) ,
354
+ Vec3 :: new (
355
+ scene_bbox. lower ( ) . x ,
356
+ scene_bbox. center ( ) . y ,
357
+ scene_bbox. lower ( ) . z ,
358
+ ) ,
322
359
1.0 ,
323
360
) ;
324
361
@@ -334,26 +371,49 @@ impl Scene {
334
371
335
372
// fill light
336
373
add_light (
337
- Vec3 :: new ( scene_bbox. upper ( ) . x , scene_bbox. lower ( ) . y , scene_bbox. lower ( ) . z ) ,
374
+ Vec3 :: new (
375
+ scene_bbox. upper ( ) . x ,
376
+ scene_bbox. lower ( ) . y ,
377
+ scene_bbox. lower ( ) . z ,
378
+ ) ,
338
379
0.75 ,
339
380
) ;
340
381
341
382
// background light
342
- add_light ( Vec3 :: new ( scene_bbox. lower ( ) . x , scene_bbox. upper ( ) . y , scene_bbox. upper ( ) . z ) , 0.5 ) ;
383
+ add_light (
384
+ Vec3 :: new (
385
+ scene_bbox. lower ( ) . x ,
386
+ scene_bbox. upper ( ) . y ,
387
+ scene_bbox. upper ( ) . z ,
388
+ ) ,
389
+ 0.5 ,
390
+ ) ;
343
391
344
392
// bottom light
345
393
add_light (
346
- Vec3 :: new ( scene_bbox. center ( ) . x , scene_bbox. lower ( ) . y , scene_bbox. center ( ) . z ) ,
394
+ Vec3 :: new (
395
+ scene_bbox. center ( ) . x ,
396
+ scene_bbox. lower ( ) . y ,
397
+ scene_bbox. center ( ) . z ,
398
+ ) ,
347
399
0.75 ,
348
400
) ;
349
401
350
402
// top light
351
403
add_light (
352
- Vec3 :: new ( scene_bbox. center ( ) . x , scene_bbox. upper ( ) . y , scene_bbox. center ( ) . z ) ,
404
+ Vec3 :: new (
405
+ scene_bbox. center ( ) . x ,
406
+ scene_bbox. upper ( ) . y ,
407
+ scene_bbox. center ( ) . z ,
408
+ ) ,
353
409
0.5 ,
354
410
) ;
355
411
356
- Scene { camera, lights, dla }
412
+ Scene {
413
+ camera,
414
+ lights,
415
+ dla,
416
+ }
357
417
}
358
418
}
359
419
0 commit comments