Skip to content

Commit

Permalink
Merge branch 'main' of github.com:jmbhughes/barnsley
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbhughes committed Feb 4, 2024
2 parents ddc0c25 + 3670e51 commit 6028fb2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use rand::prelude::*;
use rand::distributions::WeightedIndex;
use rand_distr::Distribution;
use crate::transform;
use crate::util::*;
use crate::transform::*;
use crate::image::*;
Expand All @@ -28,6 +29,13 @@ impl IFS{
distribution: WeightedIndex::new([1.]).unwrap()}
}

/// Update the IFS to new random weights and random parameters for each transform
pub fn randomize(&mut self) {
self.transforms = self.transforms.iter().map(|t| transform_from_str(t.get_name())).collect();
self.distribution = WeightedIndex::new(self.transforms.iter().map(|t| t.get_weight())).unwrap();
self.total_weight = self.transforms.iter().map(|t| t.get_weight()).sum();
}

pub fn len(&self) -> usize {
self.num_transforms
}
Expand Down Expand Up @@ -84,7 +92,6 @@ impl IFS{
fn choose_transform(&self) -> &Transform {
let mut rng = thread_rng();
self.transforms.get(self.distribution.sample(&mut rng)).unwrap()
//self.transforms.get(self.distribution.sample(&mut rng)).unwrap()
}

/// Evaluate a transform
Expand Down

0 comments on commit 6028fb2

Please sign in to comment.