@@ -23,7 +23,7 @@ pub fn init_image(sidelen: u32, source: Preset) -> (u32, Vec<SeedPos>, Vec<SeedC
2323
2424 sim. set_assignments ( assignments, sidelen) ;
2525 for cell in & mut sim. cells {
26- cell. dst_force = 0.14 ;
26+ cell. dst_force = 0.13 ;
2727 }
2828 ( seeds_n as u32 , seeds, colors, sim)
2929}
@@ -100,10 +100,10 @@ pub struct CellBody {
100100
101101const PERSONAL_SPACE : f32 = 0.95 ;
102102const MAX_VELOCITY : f32 = 6.0 ;
103- const ALIGNMENT_FACTOR : f32 = 0.7 ;
103+ const ALIGNMENT_FACTOR : f32 = 0.8 ;
104104
105105fn factor_curve ( x : f32 ) -> f32 {
106- ( x * x * x) . min ( 10 .0)
106+ ( x * x * x) . min ( 1000 .0)
107107}
108108
109109impl CellBody {
@@ -186,22 +186,11 @@ impl CellBody {
186186 self . accy -= dy * weight;
187187 } else if dist. abs ( ) < f32:: EPSILON {
188188 // if they are exactly on top of each other, push in a random direction
189- // deterministic pseudo-random push based on position
190- let x_bits = pos. xy [ 0 ] . to_bits ( ) ;
191- let y_bits = pos. xy [ 1 ] . to_bits ( ) ;
192- let mut h = x_bits ^ y_bits. rotate_left ( 16 ) ^ 0x9E3779B9 ;
193- h ^= h >> 15 ;
194- h = h. wrapping_mul ( 0x85EB_CA6B ) ;
195- h ^= h >> 13 ;
196- let hx = h;
197-
198- let mut h2 = hx ^ 0xC2B2_AE35 ;
199- h2 ^= h2 >> 16 ;
200- h2 = h2. wrapping_mul ( 0x27D4_EB2D ) ;
201- h2 ^= h2 >> 15 ;
202-
203- let r1 = ( hx as f32 ) / ( u32:: MAX as f32 ) ; // [0, 1)
204- let r2 = ( h2 as f32 ) / ( u32:: MAX as f32 ) ; // [0, 1)
189+ let seed = ( pos. xy [ 0 ] . to_bits ( ) as u64 ) ^ ( ( pos. xy [ 1 ] . to_bits ( ) as u64 ) << 32 ) ;
190+ let mut rng = frand:: Rand :: with_seed ( seed) ;
191+
192+ let r1 = rng. gen_range ( 0.0 ..1.0 ) ;
193+ let r2 = rng. gen_range ( 0.0 ..1.0 ) ;
205194
206195 self . accx += ( r1 - 0.5 ) * 0.1 ;
207196 self . accy += ( r2 - 0.5 ) * 0.1 ;
@@ -236,6 +225,7 @@ pub struct Sim {
236225 //elapsed_frames: u32,
237226 pub cells : Vec < CellBody > ,
238227 name : String ,
228+ reversed : bool ,
239229}
240230
241231impl Sim {
@@ -244,6 +234,7 @@ impl Sim {
244234 cells : Vec :: new ( ) ,
245235 //elapsed_frames: 0,
246236 name,
237+ reversed : false ,
247238 }
248239 }
249240
@@ -261,6 +252,7 @@ impl Sim {
261252 mem:: swap ( & mut cell. srcy , & mut cell. dsty ) ;
262253 cell. age = 0 ;
263254 }
255+ self . reversed = !self . reversed ;
264256 }
265257
266258 pub fn update ( & mut self , positions : & mut [ SeedPos ] , sidelen : u32 ) {
@@ -366,6 +358,22 @@ impl Sim {
366358 self . cells [ * src_idx] . stroke_id = prev. stroke_id ;
367359 }
368360 }
361+
362+ pub ( crate ) fn prepare_play ( & mut self , positions : & mut [ SeedPos ] , reverse : bool ) {
363+ if self . reversed == reverse {
364+ for ( i, cell) in self . cells . iter_mut ( ) . enumerate ( ) {
365+ positions[ i] . xy [ 0 ] = cell. srcx ;
366+ positions[ i] . xy [ 1 ] = cell. srcy ;
367+ cell. age = 0 ;
368+ }
369+ } else {
370+ for ( i, cell) in self . cells . iter ( ) . enumerate ( ) {
371+ positions[ i] . xy [ 0 ] = cell. dstx ;
372+ positions[ i] . xy [ 1 ] = cell. dsty ;
373+ }
374+ self . switch ( ) ;
375+ }
376+ }
369377}
370378
371379// pub fn preset_path_to_name(source_dir: &Path) -> String {
0 commit comments